当我线程matplotlib并且我不经常关闭图形窗口(通过鼠标 - 关闭窗口按钮)时,我收到以下错误:
Exception RuntimeError: RuntimeError('main thread is not in main loop',) in <bound method PhotoImage.__del__ of <Tkinter.PhotoImage instance at 0x7ff408080998>> ignored Exception RuntimeError: RuntimeError('main thread is not in main loop',) in <bound method PhotoImage.__del__ of <Tkinter.PhotoImage instance at 0x7ff3fbe373f8>> ignored
Tcl_AsyncDelete: async handler deleted by the wrong thread
Aborted
Run Code Online (Sandbox Code Playgroud)
我做什么:我有一个主循环调用实例的方法.该matplotlib方法由该实例的init函数进行线程化.我不能matplotlib在实例中调用方法,我不知道为什么,所以我通过__init__以下方式调用它:
def __init__(self):
....
thread = threading.Thread(target=self.drawcharts, args=())
thread.daemon = False
thread.start()
Run Code Online (Sandbox Code Playgroud)
线程方法:
def drawcharts(self):
global endthread
..do some math..
try:
plt.plot(k)
plt.plot(x1)
plt.plot(x2) …Run Code Online (Sandbox Code Playgroud)