繁体   English   中英

matplotlib(Tkinker后端)在multiprocessing.process中崩溃-如何调用XInitThreads

[英]matplotlib (Tkinker backend) crashing in multiprocessing.process - how to call XInitThreads

这个问题与这里的许多其他帖子相关,这些帖子在从流程中调出X-windows时具有相同的错误消息-似乎没有一个可行的解决方案-但首先出现问题(如我使用ipython 2.6所发现的):

我有很多长的进程,在一个python会话中使用单独的进程在parrallel中运行它们很有意义。 这些过程使用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? 如何/何时运行? 手指交叉解决了我的问题(以及此处的一些类似问题)。 我确实找到了这篇文章: 线程处理:PyQt崩溃,并显示“出队时队列中有未知请求”,但这是针对PyQt4后端的(我没有,也无法安装。)

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM