0

I have a python application that reads a big table. I use threading to perform this task, so that GUI will not be unresponsive. For example there is a "read table" button. If user presses this button, a new thread will start reading this table. Meanwhile, if the user presses the button again, before the previous thread was completed, I want the previous thread to abort and start again. Is it possible in python? I tried to set a flag and make the thread read it in regular intervals, do you think it'll be the best way? If not, what is?

alwbtc
  • 28,057
  • 62
  • 134
  • 188
  • Forcefully aborting a thread might be bad, and could cause resource leaks, and it might not even be possible on all platforms. Having some kind of flag to tell a thread to exit/start over is probably the most portable and safe. – Some programmer dude Apr 16 '14 at 10:07
  • Do I have to check that flag regularly? How will the thread check that flag, if it is busy with its real task (reading the table)? – alwbtc Apr 16 '14 at 10:08
  • 1
    See http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python – Armin Rigo Apr 16 '14 at 10:20
  • Reading a table is typically done in some kind of loop. Just add a check every X iteration through that loop. – Some programmer dude Apr 16 '14 at 10:40
  • won't it slow down the application? – alwbtc Apr 16 '14 at 10:41

0 Answers0