this is a helper module for testthreadedimport the test imports this module and this module tries to run various python library functions in their own thread as a side effect of being imported if the spawned thread doesn t complete in timeout seconds an appeared to hang message is appended to the moduleglobal errors list that list remains empty if and only if all functions tested complete this class merely runs a function in its own thread t the thread importing this module holds the import lock so if the function called by t tries to do its own imports it will block waiting for this module s import to complete bug 147376 temporaryfile hung on windows starting in python 2 4 the real cause for bug 147376 ntpath abspath caused the hang this is a helper module for test_threaded_import the test imports this module and this module tries to run various python library functions in their own thread as a side effect of being imported if the spawned thread doesn t complete in timeout seconds an appeared to hang message is appended to the module global errors list that list remains empty if and only if all functions tested complete this class merely runs a function in its own thread t the thread importing this module holds the import lock so if the function called by t tries to do its own imports it will block waiting for this module s import to complete bug 147376 temporaryfile hung on windows starting in python 2 4 the real cause for bug 147376 ntpath abspath caused the hang
TIMEOUT = 10

import threading

import tempfile
import os.path

errors = []





class Worker(threading.Thread):
    def __init__(self, function, args):
        threading.Thread.__init__(self)
        self.function = function
        self.args = args

    def run(self):
        self.function(*self.args)

for name, func, args in [
        
        ("tempfile.TemporaryFile", lambda: tempfile.TemporaryFile().close(), ()),

        
        ("os.path.abspath", os.path.abspath, ('.',)),
        ]:

    try:
        t = Worker(func, args)
        t.start()
        t.join(TIMEOUT)
        if t.is_alive():
            errors.append("%s appeared to hang" % name)
    finally:
        del t