Matplotlib 与多处理冻结计算机 [英] Matplotlib with multiprocessing freeze computer

查看:78
本文介绍了Matplotlib 与多处理冻结计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 matplotlib 和多处理时遇到问题.我启动第一个进程,在其中显示图像并选择一个区域,然后关闭图形.然后,我启动另一个过程,在其中调用定期更新的图形函数.至此,一切正常.然后,当我尝试使用SAME图形功能启动另一个进程时,它冻结了我的整个计算机,但后台进程仍然起作用...我只有这些错误之一(并不总是相同):

错误 1:

<块引用>

XIO:X服务器上的致命IO错误25(设备的不适当的ioctl):0.0"在4438个请求(已处理4438个已知请求)之后,剩下30个事件.XIO:fatal IO error 11(资源暂时不可用)在 X 服务器上 ":0.0"在 4443 个请求(4443 个已知处理)之后,还有 31 个事件.[xcb] 处理队列时的未知序列号 [xcb]这很可能是多线程客户端,而XInitThreads却没有被称为 [xcb] 中止,对此感到抱歉.Python:../../src/xcb_io.c:274: poll_for_event: 断言`!xcb_xlib_threads_sequence_lost'失败.

错误 2:

<块引用>

失败请求的 X 错误:BadIDchoice(选择了无效的资源 ID对于此连接)失败请求的主要操作码:53(X_CreatePixmap) 失败请求中的资源 ID:0x5600299 Serial请求失败的数量:4793输出中的当前序列号流:4795 XIO:严重IO错误25(设备的ioctl不适当)在X服务器:0.0"上在 4788 个请求(4788 个已知处理)之后,还有 31 个事件.XIO:致命 IO 错误 25(设备的 ioctl 不合适)开启X 服务器 ":0.0"在4793个请求(4793个已知处理)之后,还剩下32个事件.

奇怪的是,我可以完全启动几个调用图形函数的进程而没有任何问题,这是与第一个图的耦合使其不稳定.

在尝试调试时,我发现一个简单的 fig=plt.figure() 就足以使一切崩溃:事实上,对 plt 的任何调用...

我在这里和那里读过,您可以强制matplotlib使用 agg 后端,它有助于多进程,但是某些小部件不起作用,所以我想避免这种情况./p>

我真的不明白为什么在不同的过程中使用 matplotlib 会导致问题,所以如果有人可以解释原因和/或帮助我解决问题,那将非常好.

解决方案

我遇到了一个非常相似的问题,即我有一个并行生成图的类.我第一次创建该类的新实例并运行绘图功能时,一切正常.但是如果我创建一个新的实例和绘图,一切都会冻结.

我通过编写一个 bash 脚本来修复它,该脚本将依次运行带有单个类实例化 + 绘图调用代码的 python 脚本.换句话说,在一个绘图调用和下一个绘图调用之间关闭python可以使您的工作环境更加清晰,计算机不再冻结.这不是一个最佳的解决方案,但是它正在工作:)

I have an issue with matplotlib and multiprocessing. I launch a first process, where I display an image and select an area, and close the figure. Then I launch another process, where I call a graph function that is regularly updated. Up this point, eveything works fine. Then when I try to launch another process with the SAME graph function, it freeze my whole computer, BUT the background processes stil work... I only have one of these errors (it's not always the same):

error 1 :

XIO: fatal IO error 25 (Inappropriate ioctl for device) on X server ":0.0" after 4438 requests (4438 known processed) with 30 events remaining. XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0" after 4443 requests (4443 known processed) with 31 events remaining. [xcb] Unknown sequence number while processing queue [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called [xcb] Aborting, sorry about that. python: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.

error 2 :

X Error of failed request: BadIDChoice (invalid resource ID chosen for this connection) Major opcode of failed request: 53 (X_CreatePixmap) Resource id in failed request: 0x5600299 Serial number of failed request: 4793 Current serial number in output stream: 4795 XIO: fatal IO error 25 (Inappropriate ioctl for device) on X server ":0.0" after 4788 requests (4788 known processed) with 31 events remaining. XIO: fatal IO error 25 (Inappropriate ioctl for device) on X server ":0.0" after 4793 requests (4793 known processed) with 32 events remaining.

The weird part is that I can totaly launch several process calling the graph function without any issue, it's the coupling with the first plot that make it unstable.

When trying to debug, I found out that a simple fig=plt.figure() is enough to crash everything : in fact, any call to plt ...

I read here and there that you can force matplotlib to use the agg backend and it helps with the multiprocess, but some widgets doesn't work with it so I would like to avoid this.

I don't really understand why using matplotlib in differents processes could cause problems, so if anyone could explain the reasons and/or help me with a workaround, it would be very nice.

解决方案

I just had a very similar issue in which I have a class which produces plots in parallel. The first time I create a new instance of that class and run the plotting function, everything works perfectly. But if I create a new instance and plot, everything freezes.

I fixed it by writing a bash script which will in turn run a python script with the code for a single class instantiation + plot call. In other words, closing python between one plot call and the next one makes a clean slate of your working environment the computer does not freeze anymore. This is not an optimal solution, but it's working :)

这篇关于Matplotlib 与多处理冻结计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆