[issue1596321] KeyError at exit after 'import threading' in other thread

Christian Walther report at bugs.python.org
Mon Jan 18 21:40:09 CET 2010


Christian Walther <cwalther at users.sourceforge.net> added the comment:

I have the impression we're tracking two completely unrelated problems in this tracker item.

As to "needs patch" regarding my problem: Here's the solution I proposed in my original post in patch form - I'm just not sure if it is correct. I don't recommend applying this until someone who is familiar with the workings of the threading module has confirmed that removing self from _active is the right thing to do (and that what I'm doing is the accepted pythonic way of removing a dictionary entry by value).

Index: Lib/threading.py
===================================================================
--- Lib/threading.py    (revision 77598)
+++ Lib/threading.py    (working copy)
@@ -611,7 +611,11 @@
 
         try:
             with _active_limbo_lock:
-                del _active[_get_ident()]
+                for k, v in _active.iteritems():
+                    if v is self: break
+                else:
+                    assert False, "thread instance not found in _active"
+                del _active[k]
                 # There must not be any python code between the previous line
                 # and after the lock is released.  Otherwise a tracing function
                 # could try to acquire the lock again in the same thread, (in

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1596321>
_______________________________________


More information about the Python-bugs-list mailing list