design question on threading

Gonçalo Rodrigues op73418 at mail.telepac.pt
Wed Oct 16 10:53:31 EDT 2002


Hi,

I have been studying the code in the threading module and in it the
responsability of putting the Thread object in the active threads list
is on the Thread object itsef.

I want to change this and place this burden in a dedicated ThreadManager
object - with the proviso that the Thread's themselves should know about
it as little as possible, after all a Thread does not have to know that
it is managed or owned by something in another thread. This object will
have a start method with an initialized (but not started) Thread as
argument, and I have devised one way to do this that I will describe in
words. Before doing it, let me say that a Thread has a variable set from
None to an integer id that indicates it has started.

A: Issue the start method of the Thread and then enter a loop, possibly
sleeping in the middle, where we probe the variable until we get the
desired result, then we add the Thread to the active list.

Are there better ways to do this? I say better because I do not like
entering busy loops to check for something. On the other the
communication between the threads is kept to a minimum which is
something i particularly like...

All the best,
Gonçalo Rodrigues



More information about the Python-list mailing list