Another solution to How do I know when a thread quits?
consul at legio.X.com
Wed Jun 8 19:05:29 CEST 2005
On Tue, 07 Jun 2005 09:41:16 -0400, Peter Hansen wrote:
On Tue, 07 Jun 2005 06:28:33 -0700, Prashanth Ellina wrote:
> I have used the low-level thread module to write a multi-threaded app.
> tid = thread.start_new_thread(process, ())
> tid is an integer thread ident.
> the thread takes around 10 seconds to finish processing. Meanwhile the
> main thread finished execution and exits. This causes an error because
> the child thread tries to access something in the sys module which has
> already been GC'ed. I want a reliable way of knowing when the child
> thread finished execution so that I can make the main thread wait till
By reading the Python documentation I figured out to do the following:
# create an event flag to signal the completion of the thread
# create thread
task_thread = threading.Thread\
(None, name_of_thread_function, None, (thread_args...))
# clear the wait for event flag
# run thread
if main thread has nothing to do:
# wait for thread to complete (wait on event flag)
# thread has completed
# thread is still active
# so main thread can continue with more tasks
Remember to have the "task_thread" set the "task_event" flag prior to
Hope this helps.
More information about the Python-list