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.

Author hasenpfeffer
Recipients Laurent.Mazuel, Rhamphoryncus, amaury.forgeotdarc, brett.cannon, brian.curtin, bronger, cmcqueen1975, cwalther, gregory.p.smith, hasenpfeffer, pitrou
Date 2011-04-05.15:28:50
SpamBayes Score 2.1626034e-12
Marked as misclassified No
Message-id <1302017331.57.0.716655609225.issue1596321@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-04-05 15:28:51hasenpfeffersetrecipients: + hasenpfeffer, brett.cannon, gregory.p.smith, amaury.forgeotdarc, Rhamphoryncus, pitrou, bronger, cwalther, brian.curtin, cmcqueen1975, Laurent.Mazuel
2011-04-05 15:28:51hasenpfeffersetmessageid: <1302017331.57.0.716655609225.issue1596321@psf.upfronthosting.co.za>
2011-04-05 15:28:51hasenpfefferlinkissue1596321 messages
2011-04-05 15:28:50hasenpfeffercreate