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 ncoghlan
Recipients andyshorts, christian.heimes, georg.brandl, ncoghlan, ocean-city
Date 2008-02-24.07:40:45
SpamBayes Score 0.00028658504
Marked as misclassified No
Message-id <1203838847.46.0.142452713738.issue1720705@psf.upfronthosting.co.za>
In-reply-to
Content
Ahah, found the real restrictions - while it turns out the OP's
demonstration code is indeed broken, I think the warning Georg added to
the docs based on Christian's comment above is *far* too strong (hence
my somewhat annoyed message on the checkins list ;).

The actual restriction is given in Py_Finalize(): all pending imports
must be given a chance to finish before the interpreter is torn down. No
new imports should be started after that point.

The threading module takes care of this for you automatically by
registering a system shut down handler that will call the join() method
of all non-daemon threads before the interpreter starts to be torn down.
As daemon threads aren't included in this, all of their imports must be
completed before the thread is switched to daemon mode.

With the thread module, a lot more is left up to the caller (one of the
main reasons this module is being renamed to _thread in Py3k). You can
make the warnings against using *this* module directly as strong as you
want - doing so really can get you in big trouble.

As for the exact nature of the bug in the OP's demonstration code: it
takes no measures to ensure that all imports are complete before the
interpreter is shut down (and in fact deliberately goes out of its way
to break the restriction). While the approach Christian suggests
(perform all your imports from the main thread) is certainly one way to
obey the restriction, it is far from the only way (e.g. use the
threading module, and have any daemon threads only flag themselves as
such once they finish their imports).
History
Date User Action Args
2008-02-24 07:40:47ncoghlansetspambayes_score: 0.000286585 -> 0.00028658504
recipients: + ncoghlan, georg.brandl, ocean-city, andyshorts, christian.heimes
2008-02-24 07:40:47ncoghlansetspambayes_score: 0.000286585 -> 0.000286585
messageid: <1203838847.46.0.142452713738.issue1720705@psf.upfronthosting.co.za>
2008-02-24 07:40:46ncoghlanlinkissue1720705 messages
2008-02-24 07:40:45ncoghlancreate