[英]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.