Nick Coghlan added the comment:

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).

_____________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1720705>
_____________________________________
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to