我通过创建从threading.Thread继承的对象在__main__函数内部创建线程。在其运行方法内部,我打开了multiprocessing.Process,其目标函数位于模块的全局名称空间中,但出现错误:
from multiprocessing import Process, Queue
import threading
def executeTests(ScriptName, Params, MsgQueue, ResultQueue):
...
class TestRunner(threading.Thread):
def __init__(self, tests):
threading.Thread.__init__(self)
...
def run(self):
MsgQueue = Queue()
ResultQueue = Queue()
TestProcess = Process(target=executeTests, args=(ScriptName, Params, MsgQueue, ResultQueue))
TestProcess.start()
...
if __name__ == "__main__":
TestRunner(...).start()
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\Python36\lib\multiprocessing\spawn.py", line 105, in sp
awn_main
exitcode = _main(fd)
File "C:\Program Files\Python36\lib\multiprocessing\spawn.py", line 115, in _m
ain
self = reduction.pickle.load(from_parent)
AttributeError: Can't get attribute 'executeTests' on <module '__main__' (built-
in)>
答案 0 :(得分:0)
我自己解决了。 主要中缺少join()。