[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: PyQt5 QThread Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
From:       Demosthenes Koptsis <demosthenesk () gmail ! com>
Date:       2021-07-02 16:34:35
Message-ID: 88ffe349-1862-b2a6-d1c0-0b29df45ef86 () gmail ! com
[Download RAW message or body]

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@gmail.com <mailto:demosthenesk@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>

[Attachment #3 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>You are right...</p>
    <p>i did not realized the recursion...</p>
    <p>i will change the names of methods.</p>
    <p>Thank you!<br>
    </p>
    <div class="moz-cite-prefix">On 2/7/21 5:07 μ.μ., Maurizio Berti
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAPn+-XQ6A6y0DDQSYE4qZfYuidNe=depZZRZs5i0RWT3drEyCQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">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.
        <div>Just change the function name with something more
          appropriate, like "stop" or "stop and wait" and *then* call
          self.wait() there.</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">Il giorno ven 2 lug 2021 alle
          ore 07:40 Demosthenes Koptsis &lt;<a
            href="mailto:demosthenesk@gmail.com" moz-do-not-send="true">demosthenesk@gmail.com</a>&gt;
          ha scritto:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">What
          do you think of this implementation ?<br>
          <br>
          <br>
          Thread.py<br>
          <br>
          ---------------------------<br>
          <br>
          from PyQt5.QtWidgets import *<br>
          from PyQt5.QtCore import *<br>
          from MainWindow import *<br>
          import sys<br>
          import time<br>
          <br>
          <br>
          class RunThread(QtCore.QThread):<br>
               counter_value = QtCore.pyqtSignal(int)  # define new
          Signal<br>
          <br>
               def __init__(self, parent=None, counter_start=0):<br>
                   super(RunThread, self).__init__(parent)<br>
                   self.counter = counter_start<br>
                   self.is_running = True<br>
          <br>
               def run(self):<br>
                   self.is_running = True<br>
                   while self.counter &lt; 100 and self.is_running is
          True:<br>
                       time.sleep(0.5)<br>
                       self.counter += 1<br>
                       self.counter_value.emit(self.counter)  # emit new
          Signal <br>
          with value<br>
          <br>
               def stop(self):<br>
                   try:<br>
                       self.is_running = False<br>
                       self.terminate()<br>
                   except:<br>
                       pass<br>
          <br>
               def wait(self):<br>
                   try:<br>
                       self.is_running = False<br>
                       self.wait()<br>
                   except:<br>
                       pass<br>
          <br>
          class MainWindow(QWidget):<br>
               def __init__(self, parent=None):<br>
                   super(MainWindow, self).__init__(parent)<br>
                   self.ui = Ui_Form()<br>
                   self.ui.setupUi(self)<br>
                   self.center()<br>
                   #Init progressBar<br>
                   self.ui.progressBar.setValue(0)<br>
                   #Buttons<br>
                   self.ui.btnRun.clicked.connect(self.StartThread)<br>
                   self.ui.btnStop.clicked.connect(self.WaitThread)<br>
                   self.ui.dial.sliderMoved.connect(self.SetLCD)<br>
                   #Init Thread<br>
                   self.MyThread = RunThread(parent=None,
          counter_start=0)<br>
          <br>
               def SetLCD(self):<br>
                   self.ui.lcdNumber.display(self.ui.dial.value())<br>
          <br>
               def WaitThread(self):<br>
                   self.MyThread.wait()<br>
          <br>
               def StartThread(self):<br>
                   self.MyThread.start()<br>
          self.MyThread.counter_value.connect(self.SetProgressBarValue)<br>
          <br>
               def SetProgressBarValue(self):<br>
                   self.ui.progressBar.setValue(self.MyThread.counter)<br>
          <br>
               def center(self):<br>
                   # geometry of the main window<br>
                   qr = self.frameGeometry()<br>
          <br>
                   # center point of screen<br>
                   cp = QDesktopWidget().availableGeometry().center()<br>
          <br>
                   # move rectangle's center point to screen's center
          point<br>
                   qr.moveCenter(cp)<br>
          <br>
                   # top left of rectangle becomes top left of window
          centering it<br>
                   self.move(qr.topLeft())<br>
          <br>
          if __name__ == '__main__':<br>
               app = QApplication(sys.argv)<br>
               w = MainWindow()<br>
               #   Disable maximize window button<br>
               w.setWindowFlags(Qt.WindowCloseButtonHint | <br>
          Qt.WindowMinimizeButtonHint)<br>
               w.show()<br>
               sys.exit(app.exec_())<br>
          <br>
        </blockquote>
      </div>
      <br clear="all">
      <div><br>
      </div>
      -- <br>
      <div dir="ltr" class="gmail_signature">È difficile avere una
        convinzione precisa quando si parla delle ragioni del cuore. -
        "Sostiene Pereira", Antonio Tabucchi<br>
        <a href="http://www.jidesk.net" target="_blank"
          moz-do-not-send="true">http://www.jidesk.net</a></div>
    </blockquote>
  </body>
</html>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic