thread behavior with join() and import
eric jones
ej at ee.duke.edu
Mon May 8 06:08:45 EDT 2000
Hello,
I'm curious as to why the following two threads behave differently. When
the "time" module is imported within the worker thread, a join() on that
thread blocks indefinitely. If however, the import outside of the worker
thread, the join() occurs as I expected.
Removing the join() on the second thread allows it to exit normally. Why
don't "import" and join() play well together, and is there a remedy? I
really need the import to occur within the worker thread because of some
wxPython issues.
I'm using 1.5.2. The behavior is the same on both RH6.1 and NT 4.0.
thanks,
eric
----------------------------------------------------------------------------
---------------
import threading ,time
class without_import(threading.Thread):
def run(self):
time.sleep(.5)
print 'worker: without done'
class with_import(threading.Thread):
def run(self):
import time
time.sleep(.5)
print 'worker: with done'
############# this works fine
wo = without_import()
wo.start()
wo.join()
print 'main: without import done'
######## without join(), thread also terminates normally
w = with_import()
w.start()
print 'main: with import done'
"""
##### uncommenting this blocks indefinitely
w = with_import()
w.start()
w.join()
print 'main: with import done'
"""
More information about the Python-list
mailing list