【发布时间】: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