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.

classification
Title: TempFile can hang on Windows
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: arigo, tim.peters
Priority: high Keywords:

Created on 2006-04-20 18:35 by tim.peters, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
hang.py tim.peters, 2006-04-20 18:35 "import hang" and Python 2.4+ hangs
Messages (3)
msg28319 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2006-04-20 18:35
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 ;-)

msg28320 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2006-04-21 17:22
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...
msg28321 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2006-04-21 21:26
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.
History
Date User Action Args
2022-04-11 14:56:16adminsetgithub: 43257
2006-04-20 18:35:21tim.peterscreate