symbian-qemu-0.9.1-12/python-2.6.1/Lib/test/threaded_import_hangers.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 # This is a helper module for test_threaded_import.  The test imports this
       
     2 # module, and this module tries to run various Python library functions in
       
     3 # their own thread, as a side effect of being imported.  If the spawned
       
     4 # thread doesn't complete in TIMEOUT seconds, an "appeared to hang" message
       
     5 # is appended to the module-global `errors` list.  That list remains empty
       
     6 # if (and only if) all functions tested complete.
       
     7 
       
     8 TIMEOUT = 10
       
     9 
       
    10 import threading
       
    11 
       
    12 import tempfile
       
    13 import os.path
       
    14 
       
    15 errors = []
       
    16 
       
    17 # This class merely runs a function in its own thread T.  The thread importing
       
    18 # this module holds the import lock, so if the function called by T tries
       
    19 # to do its own imports it will block waiting for this module's import
       
    20 # to complete.
       
    21 class Worker(threading.Thread):
       
    22     def __init__(self, function, args):
       
    23         threading.Thread.__init__(self)
       
    24         self.function = function
       
    25         self.args = args
       
    26 
       
    27     def run(self):
       
    28         self.function(*self.args)
       
    29 
       
    30 for name, func, args in [
       
    31         # Bug 147376:  TemporaryFile hung on Windows, starting in Python 2.4.
       
    32         ("tempfile.TemporaryFile", tempfile.TemporaryFile, ()),
       
    33 
       
    34         # The real cause for bug 147376:  ntpath.abspath() caused the hang.
       
    35         ("os.path.abspath", os.path.abspath, ('.',)),
       
    36         ]:
       
    37 
       
    38     t = Worker(func, args)
       
    39     t.start()
       
    40     t.join(TIMEOUT)
       
    41     if t.is_alive():
       
    42         errors.append("%s appeared to hang" % name)