Bugs item #1596321, was opened at 2006-11-14 06:02 Message generated for change (Comment added) made by bcannon You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1596321&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: Threads Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Christian Walther (cwalther) Assigned to: Nobody/Anonymous (nobody) Summary: KeyError at exit after 'import threading' in other thread Initial Comment: Python 2.4.3 on Windows 2000, though the code in question seems unchanged in current SVN (r46919). I'm using Python embedded in a multithreaded C++ application. When 'import threading' is first done in some Python script that runs in thread A, I get the following exception when a different thread B calls Py_Finalize(): Error in atexit._run_exitfuncs: Traceback (most recent call last): File "C:\Python24\lib\atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "C:\Python24\lib\threading.py", line 636, in __exitfunc self._Thread__delete() File "C:\Python24\lib\threading.py", line 522, in __delete del _active[_get_ident()] KeyError: 680 Error in sys.exitfunc: Traceback (most recent call last): File "C:\Python24\lib\atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "C:\Python24\lib\threading.py", line 636, in __exitfunc self._Thread__delete() File "C:\Python24\lib\threading.py", line 522, in __delete del _active[_get_ident()] KeyError: 680 The reason seems to be that the threading module uses the thread ID of the calling thread as a key to store its _MainThread instance on initialization, and again the thread ID of the calling thread to delete it in its exit function. If these two threads are not the same, the described KeyError occurs. I didn't study this in all detail, but it seems to me that threading.Thread.__delete() does the wrong thing. By doing 'del _active[_get_ident()]', it removes the instance for the calling thread from the _active dictionary. What it should be doing is removing *self* from that dictionary. Is that correct? ---------------------------------------------------------------------- >Comment By: Brett Cannon (bcannon) Date: 2006-11-14 13:59 Message: Logged In: YES user_id=357491 Originator: NO Well, I don't think you should be calling Py_Finalize() from the non-main thread. That just seems unsafe to me. Regardless, though, could you write up some quick Python code that triggers this? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1596321&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com