python - 具有多处理卡住计算机的 Matplotlib

标签 python python-2.7 matplotlib multiprocessing

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

错误 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.

错误 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.

奇怪的是,我可以毫无问题地启动多个调用图形函数的进程,这是与第一个图的耦合导致它不稳定。

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

我在这里和那里读到,您可以强制 matplotlib 使用 agg 后端,它有助于多进程,但一些小部件无法使用它,所以我想避免这种情况。

我真的不明白为什么在不同的进程中使用 matplotlib 会导致问题,所以如果有人能解释原因和/或帮助我解决问题,那就太好了。

最佳答案

我刚刚遇到了一个非常相似的问题,我有一个类可以并行生成图。我第一次创建该类的新实例并运行绘图功能时,一切正常。但是,如果我创建一个新实例并绘制,一切都会卡住。

我通过编写一个 bash 脚本来修复它,该脚本将运行一个 python 脚本,其中包含用于单个类实例化 + plot 调用的代码。换句话说,在一个 plot 调用和下一个 plot 调用之间关闭 python 可以使您的工作环境变得干净,计算机不再卡住。这不是最佳解决方案,但它有效:)

关于python - 具有多处理卡住计算机的 Matplotlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31341127/

相关文章:

python - 在没有日期信息的条形图中绘制多天的数据

python - 在 matplotlib 中使用 yscale ('log' 时缺少错误栏)

python - 用python划分两个数据框

python - 将字符串拆分为多个列表

python - 如何修复 AttributeError : 'module' object has no attribute 'Client' when running python in Google Cloud Interactive Shell

python - 根据另一个列表的值顺序对字典列表进行排序

python - 导入错误 : Could not import the Python Imaging Library (PIL) required to load image files on tensorflow

python - matplotlib `hold` 关键字参数有什么作用?

python - Pandas 将另一个数据框中的值复制到我的数据框中

python - 是否可以在 Google App Engine 中使用 PyMongo?