]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug 613233: test_threadedtempfile hangs
authorTim Peters <tim.peters@gmail.com>
Wed, 25 Sep 2002 20:32:28 +0000 (20:32 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 25 Sep 2002 20:32:28 +0000 (20:32 +0000)
A possibility to deadlock (on the hidden import lock) was created here
in 2.3, seemingly when tempfile.py started to call functions in
random.py.  The cure is "the usual":  don't spawn threads as a side
effect of importing, when the spawned threads themselves do imports
(directly or indirectly), and the code that spawned the threads is
waiting for the threads to finish (they can't finish, because they're
waiting for the import lock the spawner still holds).  Worming around
this is why the "test_main" mechanism was introduced in regrest, so
it's a straightforward fix.

NOT a bugfix candidate; the problem was introduced in 2.3.

Lib/test/test_threadedtempfile.py

index 2b5ecf2511d7e290395e3bcae292f571333321f7..459ba3a1e4bd7885242c88a2d1bcadb9f31a9636 100644 (file)
@@ -25,12 +25,10 @@ import threading
 from test.test_support import TestFailed
 import StringIO
 from traceback import print_exc
+import tempfile
 
 startEvent = threading.Event()
 
-import tempfile
-tempfile.gettempdir() # Do this now, to avoid spurious races later
-
 class TempFileGreedy(threading.Thread):
     error_count = 0
     ok_count = 0
@@ -48,7 +46,7 @@ class TempFileGreedy(threading.Thread):
             else:
                 self.ok_count += 1
 
-def _test():
+def test_main():
     threads = []
 
     print "Creating"
@@ -74,6 +72,7 @@ def _test():
     if errors:
         raise TestFailed(msg)
 
+
 if __name__ == "__main__":
     import sys, getopt
     opts, args = getopt.getopt(sys.argv[1:], "t:f:")
@@ -82,5 +81,4 @@ if __name__ == "__main__":
             FILES_PER_THREAD = int(v)
         elif o == "-t":
             NUM_THREADS = int(v)
-
-_test()
+    test_main()