On 07Oct2011 10:15, Paul <poal...@gmail.com> wrote: | Tim Golden <mail <at> timgolden.me.uk> writes: | > On 07/10/2011 09:29, Paul wrote: | > > My problem is if the user doesn't select an output location and cancels the | > > dialog to go back to the selection I want to terminate the thread to avoid the | > > user opening and closing the output selection firing off a ton of threads. | > > | > > As there's no inbuilt way of killing threads I was wondering the best way to | > > prevent this? | > | > The most common approach is to have the thread monitor an event which is | > set if, for example, the user cancels. The thread may of course have to | > wait, for example, for a long-running database query to complete before | > it can discover that its time has been wasted :) [...] | My first thought was to use a flag but wouldn't the new thread see the cancel | flag and stop as well? I could set it back but then any other threads might have | been busy and not seen it while the flag was on.
I'd be inclined to dispatch threads via a control object of some kind. You'd have a default one for your program as a whole, but when you have a circumstance such as you describe instantiate a new control object. Set the cancel flag in the control objects. Have threads poll their invoking control object. That way you can have a flag that applies to your desired set of threads. Cheers, -- Cameron Simpson <c...@zip.com.au> DoD#743 http://www.cskk.ezoshosting.com/cs/ He's silly and he's ignorant, but he's got guts, and guts is enough. - Sgt. Hartmann -- http://mail.python.org/mailman/listinfo/python-list