python - PyQt error “QProcess: Destroyed while process is still running” -


when try run following pyqt code running processes , tmux, encounter error qprocess: destroyed while process still running. how can fix this?

#!/usr/bin/env python #-*- coding:utf-8 -*-  import sys pyqt4.qtcore import * pyqt4.qtgui import *  class embeddedterminal(qwidget):      def __init__(self):         qwidget.__init__(self)         self._processes = []         self.resize(800, 600)         self.terminal = qwidget(self)         layout = qvboxlayout(self)         layout.addwidget(self.terminal)         self._start_process(             'xterm',             ['-into', str(self.terminal.winid()),              '-e', 'tmux', 'new', '-s', 'my_session']         )         button = qpushbutton('list files')         layout.addwidget(button)         button.clicked.connect(self._list_files)      def _start_process(self, prog, args):         child = qprocess()         self._processes.append(child)         child.start(prog, args)      def _list_files(self):         self._start_process(             'tmux', ['send-keys', '-t', 'my_session:0', 'ls', 'enter']         )  if __name__ == "__main__":     app = qapplication(sys.argv)     main = embeddedterminal()     main.show() 

you error qprocess: destroyed while process still running when application closes , process hadn't finished.

in current code, application ends @ starts, because didn't call app.exec_(). should like:

if __name__ == "__main__":     app = qapplication(sys.argv)     main = embeddedterminal()     main.show()     sys.exit(app.exec_()) 

now, works fine, when close application still error message. need overwrite close event end process properly. works, given replace child self.child:

def closeevent(self,event):     self.child.terminate()     self.child.waitforfinished()     event.accept() 

Comments