[Patches] [ python-Patches-1240614 ] release lock on exception in threading.Thread.join()

SourceForge.net noreply at sourceforge.net
Tue Jul 19 04:25:19 CEST 2005


Patches item #1240614, was opened at 2005-07-18 19:25
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1240614&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Dirk Groeneveld (marvinalone)
Assigned to: Nobody/Anonymous (nobody)
Summary: release lock on exception in threading.Thread.join()

Initial Comment:
If an exception happens in threading.Thread.join(), the
lock self.__block never gets released. The next time
Thread.join() is called, it blocks forever. The only
exception I can think of right now that triggers this
error is KeyboardInterrupt, but there might be more.

The patch puts everything between
self.__block.acquire() and self.__block.release() into
a try ... finally block, and releases the lock in the
finally clause.

A transcript of the error follows:

>>> import threading
>>> def f():
...     while True:
...             pass
...
>>> t = threading.Thread(target = f)
>>> t.setDaemon(True)
>>> def j(t):
...     while True:
...             print "trying to join"
...             t.join(1)
...
>>> t.start()
>>> j(t)
trying to join
trying to join
trying to join
<pressed ctrl+c here>
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 4, in j
  File "/usr/lib/python2.4/threading.py", line 550, in join
    self.__block.wait(delay)
  File "/usr/lib/python2.4/threading.py", line 222, in wait
    _sleep(delay)
KeyboardInterrupt
>>> j(t)
trying to join
<python has to be killed after this line>

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1240614&group_id=5470


More information about the Patches mailing list