【问题标题】:matplotlib (Tkinker backend) crashing in multiprocessing.process - how to call XInitThreadsmatplotlib(Tkinter 后端)在 multiprocessing.process 中崩溃 - 如何调用 XInitThreads
【发布时间】:2017-09-21 01:47:29
【问题描述】:

此问题与此处的许多其他帖子有关,这些帖子在从进程中启动 X-windows 时具有相同的错误消息-似乎没有一个可行的解决方案-但首先是问题(正如我使用 ipython 2.6 发现的那样) :

我有许多长进程,在单个 python 会话中使用单独的进程并行运行它们是有意义的。这些过程使用 matplotlib.pyplot 绘制图形。但是,当调用 pyplot.show() 或 pyplot.figure() 时,进程会导致整个 python 会话崩溃,并出现以下错误:

[xcb] Unknown sequence number while processing queue
[xcb] Most likely this ia a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
python2.7: xcb_io.c:259: poll_for_event: Assertion '!xcb_xlib_threads_sequence_lost' failed.
Aborted 

我能够从 ipython 命令行以更简单的形式重现此错误:

from matplotlib import pyplot
import multiprocessing as mp
def plot():
    pyplot.plot([1,2,3,4])
    pyplot.show() #this is the line it crashes on

# the next two lines are only needed if not iython --pyplot or you have not called pyplot.ion()
pyplot.plot([1,2,3,4]) 
pyplot.show() #close plot

p=mp.process.Process(target=plot)
p.start() #crash!!!!!

检查matplotlib.get_backend() 显示我正在运行TKAgg / Tkinker 其他有相同错误的人也在使用Tkinker 制作漂亮的gui。还值得注意的是,我可以在不同的 xterm 中从单独的 ipython 会话中运行尽可能多的 plot 例程,而不会出现问题。 (给定Process 命令应该创建它自己的命名空间似乎是同一件事)。

所以我的问题是,我在哪里(在 python 中)可以找到 XIitThreads?如何/何时运行?并且手指交叉它解决了我的问题(以及这里的一些类似问题)。我确实找到了这篇文章:Threading: PyQt crashes with "unknown request in queue while dequeuing",但这是针对 PyQt4 后端(我没有也无法安装。)

编辑 - 一个警告 - 如果您将 pyplot.show() 替换为 pyplot.show(block=False),那么您将留下一个不会消失的窗口 - 可能是 pyplot.save() 的一个优势。

此外,所有在 Tkinter 或 matplotlib 中查找对 xcb_io 的调用的尝试都失败了 - 有人知道它们在哪里吗?

【问题讨论】:

    标签: python matplotlib multiprocessing


    【解决方案1】:

    如果您将 .show() 替换为 pyplot.save('foo.png'),您可能会更开心,避免尝试弹出新窗口。然后使用网络浏览器显示 *.png。

    【讨论】:

    • 不显示绘图是一种解决方法(我什至可以从 python 程序运行浏览器)但鉴于错误消息告诉我运行 XInitThreads (和其他人在创建 gui 时遇到相同的错误)它最好先尝试一下。绘制 eplot 的好处是用户可以放大查看细节。
    • 你有多个进程。有什么方法可以将一个进程用于.show(),并让工蜂将完成的地块发送给它?
    • 那些会经过泡菜吗?如果不是,那可能会很棘手。据我所知,从 Process 发回的任何东西都必须经过腌制。可能是一个很好的解决方案。
    猜你喜欢
    • 1970-01-01
    • 2017-11-01
    • 2017-08-21
    • 2015-11-08
    • 2016-12-18
    • 1970-01-01
    • 2020-01-16
    • 2012-04-05
    • 2020-03-24
    相关资源
    最近更新 更多