This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: release lock on exception in threading.Thread.join()
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: aptshansen, marvinalone, nnorwitz
Priority: normal Keywords: patch

Created on 2005-07-19 02:25 by marvinalone, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
thread_join_release_lock_on_exception.patch marvinalone, 2005-07-19 02:25 patch for locking issue in threading.Thread.join()
Messages (5)
msg48594 - (view) Author: Dirk Groeneveld (marvinalone) Date: 2005-07-19 02:25
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>
msg48595 - (view) Author: Dirk Groeneveld (marvinalone) Date: 2005-07-22 07:12
Logged In: YES 
user_id=146647

The (a?) corresponding bug report is #1171023, at
http://www.python.org/sf/1171023.
msg48596 - (view) Author: Stephen Hansen (aptshansen) Date: 2007-03-16 06:41
This is redundant in the current HEAD of the repository; there's already a try/finally with a release in it. 

Recommend close.
msg48597 - (view) Author: Stephen Hansen (aptshansen) Date: 2007-03-16 07:10
I peaked around; the patch that got applied to resolve this was 1314396 in r41524.
msg48598 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-03-16 07:21
Makes sense to me.  Thanks for the comment!
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42199
2005-07-19 02:25:19marvinalonecreate