[Flask] Simultaneous Matplotlib "QObject" error

John Robson John.Robson at usp.br
Fri Sep 9 17:26:13 EDT 2016


I found the main problem, I followed this and worked:

http://matplotlib.org/faq/howto_faq.html#howto-webapp

"matplotlib.use('Agg')" for not print, only save figures.

I also fixed other problems, I was using "plt.savefig", "plt.xxx" I 
believe that this "plt" was harming other simultaneous plots, so I 
replaced every "plt." by ".fig" and now I think is OK.

I just wonder how can I isolate each plot from other simultaneous plots, 
I'm doing this:

fig = plt.figure()
ax = fig.gca()
 > plot stuff, scatterplot, etc..., set title, lables, etc...
fig = ax.get_figure()
fig.set_tight_layout(True)
fig.savefig(filename, format='png', dpi=100, facecolor='w', 
edgecolor='k', bbox_inches='tight')
fig.clf()
plt.close(fig)

So the first "fig" instance is destroyed at the end and there is no 
"plt.xxx"

This is a good approach to isolate all plots?

Thank you,
John

On 09/08/16 21:13, John Robson wrote:
> Hi all,
>
> I have some pages that plot charts using Matplotlib, they work very
> well, but when running them simultaneously they break, with errors like:
>
> "QObject: Cannot create children for a parent that is in a different
> thread."
>
> "QObject::~QObject: Timers cannot be stopped from another thread"
>
> I wonder how to safely use Matplolib with Flask (and several
> simultaneous users plotting stuff all the time)?
>
> Thank you,
> John



More information about the Flask mailing list