1

I'm working on a tool that integrates matplotlib plots in a Pyside GUI. All work well until I close the GUI; I have this error message "python.exe has stopped working". I made several tests and I noticed wired things:

  • If i'm in running the tool with python debug, when I close the GUI I don't have this message.
  • If i'm running the tool from the shell, I don't have the error message either.

This only appear on a classic python run; whenever i close my GUI AFTER having plot something.

Here's my code:

import os
import sys
import pandas as pd
import PySide

import matplotlib
matplotlib.use('wxAgg')
matplotlib.rcParams['backend']='qt4agg'
matplotlib.rcParams['backend.qt4']='PySide'
from matplotlib.figure import figure
from matplotlib.backends.backend_qt4agg import (FigureCanvasQTAgg as FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
import matplotlib.pyplot as plt

class Main():

    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        #loading of the MainWindow and buttons initialization....

        self.MainWindow.show()
        sys.exit(app.exec_())

    def plotGeneration(self):
        fig=plt.figure(facecolor='white')
        canvas=FigureCanvas(fig)
        canvas.setParent(self.MainWindow)
        ax=fig.add_subplot(111)
        ax.set_xlabel('Date')
        ax.set_ylabel('Time')
        toolbar=NavigationToolbar(canvas, self.MainWindow, coordinates=True)
        self.MainWindow.mplwindow.addWidget(toolbar, 0,0,1,1)
        plt.clf() #tried from other post seen with this issue
        try:
            limit=self.MainWindow.limitTime.text()
            ax.plot((self.dateList[0], max(self.dateList)), (int(limit), int(limit)), 'r')
        except ValueError:
            pass
        ax.plot(self.dateList, self.timeList, 'o-')
        canvas.draw()
        self.MainWindow.gridLayoutPlot.addWidget(canvas, 0,0,1,1)
        plt.close(fig) #Also tried from other posts

if __name__ == '__main__':
    app=QtGui.QApplication(sys.argv)
    MainWindow=Main()
    MainWindow.show()
    sys.exit(app.exec_())

Nothing from other similar issues worked for me, I'm using Python 3.1 and matplotlib 1.2.0.

Does anyone have an idea ? Thanks

UPDATE

Thanks to a comment below I resolved the python31.exe crash when launching the script with a basic python run by adding this line:

self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

BUT I still have the same error message when I'm trying to compilate the script with cx_freeze. I'm using cx_freeze 4.2.3.

v_lfr
  • 63
  • 8
  • Looks like a problem when it tries to free memory... – AdrienW Jul 26 '16 at 13:13
  • I think it comes from PySide (recurrent problem). Maybe try [this](http://stackoverflow.com/a/38590440/5018771) – AdrienW Jul 26 '16 at 13:21
  • The cause is likely the use of `pyplot`. I've seen this before in my own PyQt code. When embedding matplotlib in a PySide/PyQt application you [shouldn't use `pyplot`](https://stackoverflow.com/questions/17973177/matplotlib-and-pyqt-dynamic-figure-runs-slow-after-several-loads-or-looks-messy#comment26295260_17973177), and should instead use matplotlib's object-oriented interface. See [this example](http://matplotlib.org/examples/user_interfaces/embedding_in_qt4.html). – user3419537 Jul 26 '16 at 15:13

0 Answers0