On Fri, Jul 22, 2011 at 7:29 PM, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > Is it really necessary to hold the import lock for so long? > Presumably the import lock is there to protect access to > things like sys.modules. Is that all? Could it be released > after the module code is loaded and sys.modules has been > updated, but before executing the module body?
No, because we don't know if we're keeping it until the module body is executed successfully and we don't want other threads to see the partially initialised module. There's a reason the docs say never to spawn and then wait for threads as a side effect of import (http://docs.python.org/library/threading#importing-in-threaded-code) If you want to delegate main module execution to another file, then runpy.run_module is available. Antoine's fine grained import locking patch (or something along those lines) would improve matters, but currently causes its own deadlock problems. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com