Attached is a simple module. If you try to import it ("import hang"), it prints "asking for temp file", and hangs there, never returning from its call to tempfile.TemporaryFile(). It's in fact stuck in ntpath.py, on the "from nt import _getfullpathname" line in function `abspath`. Of course hang.py spawns another thread, and is hung waiting for the import lock. That thread isn't doing any imports the _user_ knows about, and Python's standard library should be coded more defensively than this. The symptom was reported on zodb-dev today, where Martin Gfeller reported ZEO hanging on Windows for what appears to be the same reason: http://mail.zope.org/pipermail/zodb-dev/2006-April/009989.html As it says there, it looks like this problem was introduced (indirectly) by patch http://www.python.org/sf/810914 which appears to have been revision 34396 (October 2003! -- but not backported to 2.3, so nobody would notice this before 2.4). I haven't dug deeper than this, and don't know why nobody noticed ZEO hanging before ;-)
Logged In: YES user_id=4771 The general problem keeps showing up again and again. I can't find all reference (I remember more), but there are at least the following open bugs about it: #689895#683658#1175194. It would certainly help matters if we implemented something along the lines of putting a recursive lock on each module object, held while this specific module is being imported. More advanced solutions are possible too, but possibly more disruptive compatibility-wise...
Logged In: YES user_id=31435 Fixed in rev 45631 on the trunk, and rev 45632 on the 2.4 branch. Armin, I agree this could use a better approach. I settled for a micro-fix here because this specific one accounts for a report of Zope Corp's ZEO hanging on Windows, and it was an odd way to change ntpath.abspath to begin with. Note that I added a new Lib/test/threaded_import_hangers.py to check that tempfile.TemporaryFile and os.path.abspath don't hang anymore, and that's designed to make it easy to add additional tests of this kind.