[Python-checkins] python/dist/src/Lib/test test_threadedtempfile.py,1.4,1.5

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Wed, 25 Sep 2002 13:32:30 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv15813/python/Lib/test

Modified Files:
	test_threadedtempfile.py 
Log Message:
SF bug 613233: test_threadedtempfile hangs

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.


Index: test_threadedtempfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_threadedtempfile.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_threadedtempfile.py	23 Jul 2002 19:04:06 -0000	1.4
--- test_threadedtempfile.py	25 Sep 2002 20:32:28 -0000	1.5
***************
*** 26,35 ****
  import StringIO
  from traceback import print_exc
  
  startEvent = threading.Event()
  
- import tempfile
- tempfile.gettempdir() # Do this now, to avoid spurious races later
- 
  class TempFileGreedy(threading.Thread):
      error_count = 0
--- 26,33 ----
  import StringIO
  from traceback import print_exc
+ import tempfile
  
  startEvent = threading.Event()
  
  class TempFileGreedy(threading.Thread):
      error_count = 0
***************
*** 49,53 ****
                  self.ok_count += 1
  
! def _test():
      threads = []
  
--- 47,51 ----
                  self.ok_count += 1
  
! def test_main():
      threads = []
  
***************
*** 75,78 ****
--- 73,77 ----
          raise TestFailed(msg)
  
+ 
  if __name__ == "__main__":
      import sys, getopt
***************
*** 83,86 ****
          elif o == "-t":
              NUM_THREADS = int(v)
! 
! _test()
--- 82,84 ----
          elif o == "-t":
              NUM_THREADS = int(v)
!     test_main()