how can a child thread notify a parent thread its status?
MRAB
python at mrabarnett.plus.com
Fri Jul 24 19:44:36 EDT 2009
scriptlearner at gmail.com wrote:
> My parent thread keeps a counter for the number of free child workers
> (say 100) and initializes some child threads and call child.start().
> Once the number of free child workers reach 0, the parent thread will
> wait until some at least one child thread finishes and then it will
> initialize another child thread.
> My question is, how can a child thread notify the parent that it's
> done so that the parent can call join() on it? I am not sure how a
> child thread can send a signal to its parent while it may not even
> know anything about it's parent. Can you guys please provide some
> suggestions? Some code samples will be nice. Thanks.
I would create a queue ("Queue" module) and pass it to each child; the
child would put something (eg a reference to itself) in the queue when
it had finished.
More information about the Python-list
mailing list