版权声明: https://blog.csdn.net/weixin_41357300/article/details/81188981
import os
from multiprocessing import Process
class A:
def execute(self):
for index in range(2):
p1 = Process(target=self.process_task, args=("test",))
p1.start()
def process_task(self,test):
print(os.getpid())
print(test)
if __name__ == '__main__':
A().execute()
运行结果
25184
test
25296
test
如果这句写错了,多了括号,将不会启动多个进程 p1 = Process(target=self.process_task("test"), args=("test",))
17156
test
17156
test
不知道代码具体细节,为什么会如此