我正在处理来自多处理的Process库,并且试图从另一个文件中调用一个类作为一个单独的进程,但是,出现此错误:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
TypeError: 'tuple' object is not callable
,它仍然与我的标准输出存在于同一进程中:
20472 __main__
20472 CALL
internal func call
Leaving Call
Process Process-1:
#This is where the error prints out
Leaving main
其中20472是pid。
主文件:
import CALL
from multiprocessing import Process
import os
if __name__ == '__main__':
print(os.getpid(),__name__)
p = Process(target=(CALL.Call(),))
p.start()
p.join()
print("Leaving main")
import os
调用类文件:
class Call():
def __init__(self):
print(os.getpid(), __name__)
self.internal()
def __exit__(self):
print("Leaving Call")
def internal(self):
print("internal func call")
self.__exit__()
答案 0 :(得分:0)
@Jeronimo在评论中回答-更改
p = Process(target=(call.Call(),)
到
p = Process(target=(call.Call))
是提供正确输出的解决方案:
2965 __main__
2966 CALL
internal func call
Leaving Call
Leaving main
为被调用的类提供单独的过程。