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.
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
21 class Worker(threading
.Thread
):
22 def __init__(self
, function
, args
):
23 threading
.Thread
.__init
__(self
)
24 self
.function
= function
28 self
.function(*self
.args
)
30 for name
, func
, args
in [
31 # Bug 147376: TemporaryFile hung on Windows, starting in Python 2.4.
32 ("tempfile.TemporaryFile", tempfile
.TemporaryFile
, ()),
34 # The real cause for bug 147376: ntpath.abspath() caused the hang.
35 ("os.path.abspath", os
.path
.abspath
, ('.',)),
38 t
= Worker(func
, args
)
42 errors
.append("%s appeared to hang" % name
)