在Python3.4.1中同时执行两个不同的函数

2024-09-28 22:03:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我看过很多关于这个话题的例子,但是我找不到适合我的答案。我需要你的帮助来了解这个问题的诀窍。 假设有两个函数funA()和funB()。他们的论点完全相同。函数返回两个独立的输出,即pandas系列对象。我想在没有GIL的情况下同时执行这些功能。 下面是我的代码示例:

from multiprocessing import Process
from queue import Queue
q1 = Queue()
q2 = Queue()
res1 = Process(target=funA,args=(a,b,c,q1))
res1.start()
res2 = Process(target=funB,args=(a,b,c,q2))
res2.start()
res1.join()
res2.join()
result1 = q1.get()
result2 = q2.get()

上述代码给出了以下回溯:

^{pr2}$

我已经通过了以下线程,比如http://sebastianraschka.com/Articles/2014_multiprocessing_intro.htmlConcurrently run two functions that take parameters and return lists?Make 2 functions run at the same time

请帮帮我。提前谢谢你。在


Tags: 函数代码fromimporttargetqueueargsmultiprocessing