无法在Queu中放入()和get()更大的数据帧

2024-06-11 02:58:10 发布

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

下面的代码模拟了我面临的多处理问题。在

有两个函数-f1f2,它们将包含n行的(pandas)数据帧返回到调用函数run-fns(n)。这两个功能将并行运行。在

对于n的较小值(例如n<;=700),该代码可以正常工作,但对于n的较大值(例如n>;=7000),代码将冻结。在

我尝试过使用不同的maxsize值调用Queue([maxsize]),其中包括默认值、0、-1和许多其他大小不等的数字,但这种行为没有改变。在

任何解决方案、解决办法或替代方法都将是非常受欢迎的。我还有一个第二个问题:我真的需要包括吗

if __name__ == "__main__":

在什么地方?如果是,在哪里?在

代码: f1返回n行和3列,f2返回n行和5列。数据帧是用随机生成的整数构建的。

^{pr2}$

Tags: 数据函数run代码ltgt功能pandas
1条回答
网友
1楼 · 发布于 2024-06-11 02:58:10

您正面临一个典型的问题,该问题记录在多处理programming guidelines中。在

Bear in mind that a process that has put items in a queue will wait before terminating until all the buffered items are fed by the “feeder” thread to the underlying pipe. (The child process can call the Queue.cancel_join_thread method of the queue to avoid this behaviour.)

This means that whenever you use a queue you need to make sure that all items which have been put on the queue will eventually be removed before the process is joined. Otherwise you cannot be sure that processes which have put items on the queue will terminate.

您需要确保在加入流程之前获得数据。在

# start the processes
p1.start()
p2.start()
# drain the queues
df1 = q1.get()
df2 = q2.get()
# then join the queues
p1.join()
p2.join()

return df1, df2

相关问题 更多 >