By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

Help with Threading

P: n/a
Hi

I am fairly new to Python threading and my needs are simple(!)

I want to establish a number of threads each of which work on the same
computationally intensive problem in different ways.

I am using the thread module rather than the threading module.

My problem is I can't see how (when one thread completes) to ensure that the
other threads terminate immediately.

Appreciate some simple advice

Phil
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Mon, 24 Jan 2005 05:15:07 GMT, "Philip Smith"
<as********@blueyonder.co.uk> declaimed the following in
comp.lang.python:

My problem is I can't see how (when one thread completes) to ensure that the
other threads terminate immediately.
I presume your threads contain some sort of loop structure at
some stage...

Insert a non-blocking test on some shared condition variable,
and have the thread terminate /itself/ when the condition is set. The
condition would need to be set, by your code, by whichever thread should
complete first, on its own.

May not even need a condition/event/lock -- a globally shared
variable might be sufficient.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 18 '05 #2

P: n/a
Philip Smith a écrit :
Hi

I am fairly new to Python threading and my needs are simple(!)

I want to establish a number of threads each of which work on the same
computationally intensive problem in different ways.

I am using the thread module rather than the threading module.

My problem is I can't see how (when one thread completes) to ensure that the
other threads terminate immediately.

Appreciate some simple advice

Phil


With Python's threads, you have to handle this kindd a feature yourself.
For example, you can create a single object containing a boolean set to
False by default. When one of your algorithm finishes, the boolean is
set to True. All your algorithm should regularly test this boolean and
exit if it is True ! Note that the boolean has to be inside another
object because Boolean types is not mutable. Now, if you really want to
be able to "kill" your threads, you will need another thread interface.
For example, Qt threads allows that ... and WxPython offers you some
functions to do exactly what I described.

Pierre
Jul 18 '05 #3

P: n/a
I use threading.Thread as outlined in this recipe:
http://aspn.activestate.com/ASPN/Coo...n/Recipe/65448

Jul 18 '05 #4

P: n/a

<wi******@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
I use threading.Thread as outlined in this recipe:
http://aspn.activestate.com/ASPN/Coo...n/Recipe/65448
Thanks

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.