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

hasenpfeffer report at bugs.python.org
Tue Apr 5 17:28:51 CEST 2011


hasenpfeffer <hasenpfeffer at rabbittsoup.com> added the comment:

I encountered this issue recently in Python 3.2 and wanted to make some observations about it.

The real problem here is not the KeyError.  Though the suggested patches would fix the KeyError symptom, they do not fix the underlying issue.  The underlying issue is the threading module assumes that it is imported from the Python main thread.  When alien threads exist, the threading module may be imported (directly or indirectly) from a thread that is not the Python main thread, causing the wrong thread to be marked as the Python main thread.

The resulting problems of the wrong thread being marked as the Python main thread appear to be minor.  The KeyError at exit is one of them.  Another problem I encountered was with confusion in a threaded debugger that displayed my alien thread as the Python main thread, and the Python main thread as the alien thread.

In my project I can easily work around this by importing the threading module in a root package that is extremely likely to be imported from the Python main thread, causing the correct thread to be marked as the main thread.

Since I have a workaround for my project, in addition to the relatively minor issues that result from this behavior, I haven't spent any time looking into how to fix the underlying issue.  If I have the time, I'll suggest one.

----------
nosy: +hasenpfeffer
versions: +Python 2.7, Python 3.2 -Python 2.6, Python 3.1

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


More information about the Python-bugs-list mailing list