【问题标题】:Python multiprocessing -> can not spawn Process within threadPython多处理->无法在线程内生成进程
【发布时间】:2018-09-06 10:01:12
【问题描述】:

我通过创建一个继承自 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)>

【问题讨论】:

    标签: python-3.6 windows-7-x64


    【解决方案1】:

    我自己解决了。 ma​​in 中缺少 join()。

    【讨论】:

      猜你喜欢
      • 2018-10-27
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 2021-07-16
      • 1970-01-01
      • 2012-01-20
      • 2020-08-12
      • 1970-01-01
      相关资源
      最近更新 更多