Threading troubles

Jeremy Jones zanesdad at bellsouth.net
Wed Sep 10 19:44:21 CEST 2003


* Monda.Laszlo at stud.u-szeged.hu (Monda.Laszlo at stud.u-szeged.hu) wrote:
<snip>
> 
> I want to control the execution of all threads from the main thread. I mean 
> stopping, continuing and terminating other threads. However as I've read in the 
> libc manual, there is no way to specify signal handlers for individual threads. 
> Actally I don't even know how could I signal any threads from Python at all. Any 
> workaround would be greatly appreciated.
> 

Not sure if it's possible.  Someone else on the list can correct me if I'm
wrong.  I did find the following post to c.l.p dated 2-19-2003:

http://groups.google.com/groups?q=python+kill+thread&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=mailman.1045698656.1301.python-list%40python.org&rnum=6

This post includes a patch to the Python interpreter that will allow the
killing of a thread in Python.  Not sure if that gets you any closer to
your goal.  I would strongly recommend that you think about the problem you
are trying to solve and see if there is a better solution than
starting/stopping/resuming threads (if that's even possible).  A better
approach would be to break down the tasks that you want your threads to
accomplish into smaller pieces, possibly maintain state somewhere (either a
thread-safe container if it's going to be accessed by the threads or in a
plain-old container if the main thread is going to manage state) and have
your main thread delegate the activity.  A couple of excellent resources
for dealing with threads is the Python standard library Queue and there is
a recipe out on activestate that shows how to implement a thread pool
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/203871).  I don't
know exactly what you are trying to do, so maybe starting/stopping/resuming
threads is the correct approach.  I've just found that, typically, breaking
things down a little more is a more manageable approach that is easier to
wrap your head around.


Jeremy Jones
 





More information about the Python-list mailing list