473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help with Threading

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
4 1137
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
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
I use threading.Thread as outlined in this recipe:
http://aspn.activestate.com/ASPN/Coo...n/Recipe/65448

Jul 18 '05 #4

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
1
by: Ognjen Bezanov | last post by:
Hi, all Thanks all of you who helped me with the threading and queues issue. I am trying to get it working but I am having problems. When I try to run the following: cmddata =...
0
by: Maxwell Hammer | last post by:
Hope someone can help with a problem I'm having. A python program I wrote terminates with the following traceback. *** start traceback *** Error in atexit._run_exitfuncs: Traceback (most recent...
2
by: hnkien | last post by:
Hi, I am writing a windows service with threading.timer for 10 seconds but it didn't work. Here are my code: namespace SchedulerService { public class ScheduleService :...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
10
by: MikeScullion | last post by:
I have set up this thread so my program doesn't hang while I call a cpu intensive bit of code: System.Threading.ThreadStart ThreadEncoderStart = new...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
3
by: dedalusenator | last post by:
Hello Folks, My first posting here and I am a stuck in figuring out the exact way to update a global variable from within a function that doesnt return any value (because the function is a...
1
by: JoeSox | last post by:
I have two threads going class guiThread(threading.Thread) class mainThread(threading.Thread) Within the guiThread, I have an instance of class GUIFramework(Frame) in this Tkinter instance I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.