PyQt5 QThread Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

Demosthenes Koptsis demosthenesk at gmail.com
Fri Jul 2 17:34:35 BST 2021


You are right...

i did not realized the recursion...

i will change the names of methods.

Thank you!

On 2/7/21 5:07 μ.μ., Maurizio Berti wrote:
> Do not overwrite important methods with names that don't really match 
> what they're doing. Also, your implementation will cause recursion, 
> which is clearly not good.
> Just change the function name with something more appropriate, like 
> "stop" or "stop and wait" and *then* call self.wait() there.
>
> Il giorno ven 2 lug 2021 alle ore 07:40 Demosthenes Koptsis 
> <demosthenesk at gmail.com <mailto:demosthenesk at gmail.com>> ha scritto:
>
>     What do you think of this implementation ?
>
>
>     Thread.py
>
>     ---------------------------
>
>     from PyQt5.QtWidgets import *
>     from PyQt5.QtCore import *
>     from MainWindow import *
>     import sys
>     import time
>
>
>     class RunThread(QtCore.QThread):
>          counter_value = QtCore.pyqtSignal(int)  # define new Signal
>
>          def __init__(self, parent=None, counter_start=0):
>              super(RunThread, self).__init__(parent)
>              self.counter = counter_start
>              self.is_running = True
>
>          def run(self):
>              self.is_running = True
>              while self.counter < 100 and self.is_running is True:
>                  time.sleep(0.5)
>                  self.counter += 1
>                  self.counter_value.emit(self.counter)  # emit new Signal
>     with value
>
>          def stop(self):
>              try:
>                  self.is_running = False
>                  self.terminate()
>              except:
>                  pass
>
>          def wait(self):
>              try:
>                  self.is_running = False
>                  self.wait()
>              except:
>                  pass
>
>     class MainWindow(QWidget):
>          def __init__(self, parent=None):
>              super(MainWindow, self).__init__(parent)
>              self.ui = Ui_Form()
>              self.ui.setupUi(self)
>              self.center()
>              #Init progressBar
>              self.ui.progressBar.setValue(0)
>              #Buttons
>              self.ui.btnRun.clicked.connect(self.StartThread)
>              self.ui.btnStop.clicked.connect(self.WaitThread)
>              self.ui.dial.sliderMoved.connect(self.SetLCD)
>              #Init Thread
>              self.MyThread = RunThread(parent=None, counter_start=0)
>
>          def SetLCD(self):
>              self.ui.lcdNumber.display(self.ui.dial.value())
>
>          def WaitThread(self):
>              self.MyThread.wait()
>
>          def StartThread(self):
>              self.MyThread.start()
>     self.MyThread.counter_value.connect(self.SetProgressBarValue)
>
>          def SetProgressBarValue(self):
>              self.ui.progressBar.setValue(self.MyThread.counter)
>
>          def center(self):
>              # geometry of the main window
>              qr = self.frameGeometry()
>
>              # center point of screen
>              cp = QDesktopWidget().availableGeometry().center()
>
>              # move rectangle's center point to screen's center point
>              qr.moveCenter(cp)
>
>              # top left of rectangle becomes top left of window
>     centering it
>              self.move(qr.topLeft())
>
>     if __name__ == '__main__':
>          app = QApplication(sys.argv)
>          w = MainWindow()
>          #   Disable maximize window button
>          w.setWindowFlags(Qt.WindowCloseButtonHint |
>     Qt.WindowMinimizeButtonHint)
>          w.show()
>          sys.exit(app.exec_())
>
>
>
> -- 
> È difficile avere una convinzione precisa quando si parla delle 
> ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi
> http://www.jidesk.net <http://www.jidesk.net>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210702/583d7081/attachment.htm>


More information about the PyQt mailing list