[Python-checkins] r45632 - in python/branches/release24-maint: Lib/ntpath.py Lib/test/test_threaded_import.py Lib/test/threaded_import_hangers.py Misc/NEWS (original) (raw)
tim.peters python-checkins at python.org
Fri Apr 21 23:22:01 CEST 2006
- Previous message: [Python-checkins] r45631 - in python/trunk: Lib/ntpath.py Lib/test/test_threaded_import.py Lib/test/threaded_import_hangers.py Misc/NEWS
- Next message: [Python-checkins] r45633 - python/branches/release24-maint/Misc/NEWS
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: tim.peters Date: Fri Apr 21 23:22:00 2006 New Revision: 45632
Added: python/branches/release24-maint/Lib/test/threaded_import_hangers.py - copied unchanged from r45631, python/trunk/Lib/test/threaded_import_hangers.py Modified: python/branches/release24-maint/Lib/ntpath.py python/branches/release24-maint/Lib/test/test_threaded_import.py python/branches/release24-maint/Misc/NEWS Log: Merge rev 45631 from trunk.
SF bug #1473760 TempFile can hang on Windows.
Python 2.4 changed ntpath.abspath to do an import inside the function. As a result, due to Python's import lock, anything calling abspath on Windows (directly, or indirectly like tempfile.TemporaryFile) hung when it was called from a thread spawned as a side effect of importing a module.
This is a depressingly frequent problem, and deserves a more general fix. I'm settling 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 abspath to begin with (ntpath needs a different implementation depending on whether we're actually running on Windows, and the obvious way to arrange for that is not to bury a possibly-failing import inside the function).
Note that if/when other micro-fixes of this kind get made, the new Lib/test/threaded_import_hangers.py is a convenient place to add tests for them.
Modified: python/branches/release24-maint/Lib/ntpath.py
--- python/branches/release24-maint/Lib/ntpath.py (original) +++ python/branches/release24-maint/Lib/ntpath.py Fri Apr 21 23:22:00 2006 @@ -482,27 +482,28 @@ # Return an absolute path. -def abspath(path): - """Return the absolute version of a path""" - try: - from nt import _getfullpathname - except ImportError: # Not running on Windows - mock up something sensible. - global abspath - def _abspath(path): - if not isabs(path): - path = join(os.getcwd(), path) - return normpath(path) - abspath = _abspath - return _abspath(path)
- if path: # Empty path must return current working directory.
try:
path = _getfullpathname(path)
except WindowsError:
pass # Bad path - return unchanged.
- else:
path = os.getcwd()
- return normpath(path)
+try:
- from nt import _getfullpathname
- +except ImportError: # not running on Windows - mock up something sensible
- def abspath(path):
"""Return the absolute version of a path."""
if not isabs(path):
path = join(os.getcwd(), path)
return normpath(path)
- +else: # use native Windows method on Windows
- def abspath(path):
"""Return the absolute version of a path."""
if path: # Empty path must return current working directory.
try:
path = _getfullpathname(path)
except WindowsError:
pass # Bad path - return unchanged.
else:
path = os.getcwd()
return normpath(path)
realpath is a no-op on systems without islink support
realpath = abspath
Modified: python/branches/release24-maint/Lib/test/test_threaded_import.py
--- python/branches/release24-maint/Lib/test/test_threaded_import.py (original) +++ python/branches/release24-maint/Lib/test/test_threaded_import.py Fri Apr 21 23:22:00 2006 @@ -6,7 +6,7 @@
randrange, and then Python hangs.
import thread -from test.test_support import verbose, TestSkipped +from test.test_support import verbose, TestSkipped, TestFailed
critical_section = thread.allocate_lock() done = thread.allocate_lock() @@ -25,6 +25,23 @@ if finished: done.release()
+def test_import_hangers():
- import sys
- if verbose:
print "testing import hangers ...",
- from test import threaded_import_hangers
- try:
if threaded_import_hangers.errors:
raise TestFailed(threaded_import_hangers.errors)
elif verbose:
print "OK."
- finally:
# In case this test is run again, make sure the helper module
# gets loaded from scratch again.
del sys.modules['test.threaded_import_hangers']
Tricky: When regrtest imports this module, the thread running regrtest
grabs the import lock and won't let go of it until this module returns.
All other threads attempting an import hang for the duration. Since
@@ -53,5 +70,7 @@ print "OK." done.release()
- test_import_hangers()
- if name == "main": test_main()
Modified: python/branches/release24-maint/Misc/NEWS
--- python/branches/release24-maint/Misc/NEWS (original) +++ python/branches/release24-maint/Misc/NEWS Fri Apr 21 23:22:00 2006 @@ -29,6 +29,9 @@ Library
+- Bug #1473760: tempfile.TemporaryFile()
could hang on Windows, when
+ called from a thread spawned as a side effect of importing a module.
+
- The __del__
method of class local
in module _threading_local
returned before accomplishing any of its intended cleanup.
@@ -43,6 +46,9 @@
raise an exception some day. But dicts have been allowed, and "mostly
worked", so support for them won't go away without warning.
+- New modules: setuptools, easy_install, and pkg_resources, to support
+ building, installing, and using Python eggs, respectively.
+
Tools/Demos
- Previous message: [Python-checkins] r45631 - in python/trunk: Lib/ntpath.py Lib/test/test_threaded_import.py Lib/test/threaded_import_hangers.py Misc/NEWS
- Next message: [Python-checkins] r45633 - python/branches/release24-maint/Misc/NEWS
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]