multithreading - pyqt4 qthread crashes python -


here code, created copying various tutorials , posts:

import sys  pyqt4.qtgui import * pyqt4.qtcore import qobject, pyqtsignal, qthread  class worker(qthread):     def __init__(self):          qthread.__init__(self)  class mainwindow(qwidget):      def __init__(self):         super().__init__()          worker = worker()         worker.start()  if __name__ == '__main__':     app = qapplication(sys.argv)     window = mainwindow()     window.resize(640, 480)     window.show()     sys.exit(app.exec_()) 

this pretty simple, when run python crashes immediately. i'm using anaconda3 , i'm pretty darn sure python environment set correctly, wrong. on windows 10, 64-bit, anaconda3 python 3.5 (64-bit). installed qt4 using conda.

your code crashing because worker thread being destroyed while running. happens because being created local variable within constructor of mainwindow. after __init__() completes , worker falls out of scope subject being removed python's garbage collector. in order avoid happening can assign worker member of mainwindow class.

class mainwindow(qwidget):     def __init__(self):         super().__init__()         self.worker = worker()         self.worker.start() 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -