473,698 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1154
On Mon, 24 Jan 2005 05:15:07 GMT, "Philip Smith"
<as********@blu eyonder.co.uk> declaimed the following in
comp.lang.pytho n:

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.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.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.Threa d as outlined in this recipe:
http://aspn.activestate.com/ASPN/Coo...n/Recipe/65448

Jul 18 '05 #4

<wi******@hotma il.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
I use threading.Threa d 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
2978
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 get_all_files(path): """return all files of folder path, scan with subfolders
1
1476
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 = mediaplay.initcommandqueue() #initiates the Queue to send commands down
0
1233
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 call last): File "/usr/lib/python2.4/atexit.py", line 22, in _run_exitfuncs func(*targs, **kargs) File "/usr/lib/python2.4/threading.py", line 636, in __exitfunc self._Thread__delete()
2
8461
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 : System.ServiceProcess.ServiceBase { private System.ComponentModel.IContainer components; protected System.Threading.Timer tmrThreadingTimer;
22
4061
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
1606
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 System.Threading.ThreadStart(myEncoder.EncodeFromConsole); System.Threading.Thread Thread_myEncoder = new System.Threading.Thread(ThreadEncoderStart); Thread_myEncoder.Name = "myEncoder"; Thread_myEncoder.Priority = System.Threading.ThreadPriority.BelowNormal;
5
3102
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 i used time.sleep in while, the function in while never executed. then i found something about Timer but couldnt realize any algorithm in my mind.
15
2574
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 determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
3
12777
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 target of the thread and I dont know how exactly return would work in such a case). I am sure I am missing something very fundamental here. The essential pieces of my code that cause the problem would be something like this:...
1
1233
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 have a ListBox. The second thread, mainThread, has an instance of a custom class the will need to send out text or other objects to the gui.
0
8680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7738
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.