Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib exiting error

Consider the following simple python code:

import matplotlib.pyplot as mplot 
mplot.plot([1,2,3,4],[1,2,3,4])

This script has no problems when the script runs, however if I close the python console (by clicking the red x), I get the following error:

Fatal Python error: PyEval_RrestoreThread: NULL tstate

This problem does not occur if I use ctrl+Z to exit the python console. It seems to me that there is some hanging process that isn't terminated properly if I exist the first way. I've attempted adding

mplot.close('all')

to the end of the script, but I get the following resulting error:

can't invoke "event" command: application has been destroyed while executing 
"event generate $w <<ThemeChanged>>"
(procedure "ttk::ThemeChanged" line 6)
invoke from within
"ttk::ThemeChanged"

I am running Python 3.3 x86. Could anyone help me understand this issue?

Thanks!

like image 802
Sergiy Avatar asked Feb 26 '14 23:02

Sergiy


1 Answers

The issue is that the standard Python interpreter isn't built with knowledge of how to handle graphical user interfaces. Without going into detail it looks like matplotlib was trying to close down a thread that doesn't exist.

There's an explanation of the causes at http://matplotlib.org/users/shell.html and pointers to discussions about workarounds.

The simplest answer is to use IPython, which is matplotlib aware as the reference explains. If this isn't an option you may have to dig deeper.

like image 134
holdenweb Avatar answered Oct 24 '22 04:10

holdenweb