Matplotlib-Tcl_AsyncDelete:异步处理程序被错误的线程删除了吗? [英] Matplotlib - Tcl_AsyncDelete: async handler deleted by the wrong thread?

查看:1374
本文介绍了Matplotlib-Tcl_AsyncDelete:异步处理程序被错误的线程删除了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问这个问题是因为我无法解决中的一个问题(实际上在纯Python中就可以了),从而导致出现RuntimeError: tcl_asyncdelete async handler deleted by the wrong thread.这与我在Django中渲染matplotlib图的方式有关.我这样做的方式是:

I'm asking this question because I can't solve one problem in Python/Django (actually in pure Python it's ok) which leads to RuntimeError: tcl_asyncdelete async handler deleted by the wrong thread. This is somehow related to the way how I render matplotlib plots in Django. The way I do it is:

...
import matplotlib.pyplot as plt
...
fig = plt.figure()
...
plt.close()

我极大地减少了我的代码.但是要抓住的是-即使我只有一行代码:

I extremely minimized my code. But the catch is - even if I have just one line of code:

fig = plt.figure()

我看到此RuntimeError发生了.我希望我能解决这个问题,如果我知道在Python/Django中关闭/清理/销毁图表的正确方法.

I see this RuntimeError happening. I hope I could solve the problem, If I knew the correct way of closing/cleaning/destroying plots in Python/Django.

推荐答案

默认情况下,matplotlib使用TK gui工具箱,当您在不使用工具箱(即到文件或字符串)的情况下渲染图像时,matplotlib仍会实例化一个没有显示的窗口,导致各种问题.为了避免这种情况,您应该使用Agg后端.可以这样激活它-

By default matplotlib uses TK gui toolkit, when you're rendering an image without using the toolkit (i.e. into a file or a string), matplotlib still instantiates a window that doesn't get displayed, causing all kinds of problems. In order to avoid that, you should use an Agg backend. It can be activated like so --

import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot

有关更多信息,请参阅matplotlib文档- http://matplotlib .org/faq/howto_faq.html#matplotlib-in-a-web-application-server

For more information please refer to matplotlib documentation -- http://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server

这篇关于Matplotlib-Tcl_AsyncDelete:异步处理程序被错误的线程删除了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆