Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Signal slow for the first few times. (Pyqt5)
QtWS25 Last Chance

Signal slow for the first few times. (Pyqt5)

Scheduled Pinned Locked Moved Unsolved Qt for Python
13 Posts 4 Posters 959 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Igor86
    wrote on last edited by
    #1

    Hi all!

    i am facing a strange problem here that I have no clue on how to solve and where it comes from.

    i have 2 different thread: the main Thread and another one called the worker.

    In the main Thread i emit a signal, that is connected to the slot in the worker thread. here the relevant code:

    in my Main.py:

    self.thread = QThread()
    self.worker = worker.Worker()
    self.worker.moveToThread(self.thread)
    self.startCameraSignal.connect(self.worker.get_color)        
    self.thread.start(priority=QThread.Priority.HighestPriority)
    
    ....
    
    self.startCameraSignal.emit(id_c)
    log.debug("Emitted Start camera 1.3 - " + str(time.time()))
    

    in my worker.py file:

    def get_color(self, idin):
           log.debug("Got Start camera signal - " + str(time.time()))
    

    The code itself works as expected, but i am experiencing the problem that after i reboot the pc, the first time this signal is sent out, the slot sees it only after a few seconds.. anything between 3 and 6 seconds..

    8186a250-3415-4f02-ae05-e6ef822d3fee-image.png

    after the first time, it works great and it is almost instant.

    does anybody have an explanation for this and even better, a way to solve this issue?

    Any help is greatly appreciated.

    Thank you!

    best regards

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      This does sound strange.

      Which version of PyQt5 are you using ?
      On which OS ?
      With which version of Python ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        This does sound strange.

        Which version of PyQt5 are you using ?
        On which OS ?
        With which version of Python ?

        I Offline
        I Offline
        Igor86
        wrote on last edited by
        #3

        @SGaist

        I am on a Windows 10 IoT Enterprise LTSC system.
        To troubleshoot I tried to disable everything:

        Firewall, Microsoft defender (completely disabled through safe mode), notifications, updates, everything that could be esecuted randomly

        python is 3.8.10
        pyqt is 5.15.7

        Thanks for your help

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          This does sound strange.

          Which version of PyQt5 are you using ?
          On which OS ?
          With which version of Python ?

          I Offline
          I Offline
          Igor86
          wrote on last edited by
          #4

          @SGaist

          i Just tried with Python 3.10.10 and pyqt5 5.15.10

          same problem..

          JonBJ 1 Reply Last reply
          0
          • jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by
            #5

            PyQt's slot decorator is documented as reducing the amount of memory used and is slightly faster. I haven't attempted to verify the statement, but it looks like a cheap experiment to try.

            Another experiment is to "prime" the worker thread by sending an unrelated signal to determine if the delay is related to the thread, the worker object, or the particular slot.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            I 1 Reply Last reply
            1
            • I Igor86

              @SGaist

              i Just tried with Python 3.10.10 and pyqt5 5.15.10

              same problem..

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Igor86
              I agree with both of @jeremy_k's points to try.

              Also, would you be prepared to give it a quick go using PySide2 (equivalent to PyQt5, so not PySide6 which is PyQt6)? Usually there is barely anything to change. If by chance PySide2 does not behave like this it would indicate a PyQt5 issue.

              I 1 Reply Last reply
              0
              • JonBJ JonB

                @Igor86
                I agree with both of @jeremy_k's points to try.

                Also, would you be prepared to give it a quick go using PySide2 (equivalent to PyQt5, so not PySide6 which is PyQt6)? Usually there is barely anything to change. If by chance PySide2 does not behave like this it would indicate a PyQt5 issue.

                I Offline
                I Offline
                Igor86
                wrote on last edited by
                #7

                @JonB thank you, i am trying the pyside option you posted, but i am having difficulties as i am getting this error: cannot import name 'uic' from 'PySide2'

                any idea on what i have to do in this case? i am an occasional python progger and not experienced at all.. thank you

                JonBJ 1 Reply Last reply
                0
                • I Igor86

                  @JonB thank you, i am trying the pyside option you posted, but i am having difficulties as i am getting this error: cannot import name 'uic' from 'PySide2'

                  any idea on what i have to do in this case? i am an occasional python progger and not experienced at all.. thank you

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @Igor86 said in Signal slow for the first few times. (Pyqt5):

                  cannot import name 'uic' from 'PySide2'

                  Unfortunately that is to do with the one major difference between PyQt and PySide if you are using .ui file from Designer. I can't remember what you have to change, easy for you if you are a programmer but not if not and I don't use PyQt/PySide regularly to tell you, so you may have to leave this test. Unless a Python person wants to tell you what to alter....

                  1 Reply Last reply
                  0
                  • jeremy_kJ jeremy_k

                    PyQt's slot decorator is documented as reducing the amount of memory used and is slightly faster. I haven't attempted to verify the statement, but it looks like a cheap experiment to try.

                    Another experiment is to "prime" the worker thread by sending an unrelated signal to determine if the delay is related to the thread, the worker object, or the particular slot.

                    I Offline
                    I Offline
                    Igor86
                    wrote on last edited by
                    #9

                    @jeremy_k @JonB the problem was solved by adding the @pyqtSlot decorator.

                    Thank you very much for your help!

                    jeremy_kJ JonBJ 2 Replies Last reply
                    2
                    • I Igor86

                      @jeremy_k @JonB the problem was solved by adding the @pyqtSlot decorator.

                      Thank you very much for your help!

                      jeremy_kJ Offline
                      jeremy_kJ Offline
                      jeremy_k
                      wrote on last edited by
                      #10

                      @Igor86 Thanks for running and reporting on the experiment.

                      Asking a question about code? http://eel.is/iso-c++/testcase/

                      1 Reply Last reply
                      0
                      • I Igor86

                        @jeremy_k @JonB the problem was solved by adding the @pyqtSlot decorator.

                        Thank you very much for your help!

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #11

                        @Igor86
                        Glad that sorted you out. I nearly suggested @pyqtslot but could not see from the description why that would make such an initial difference of several seconds, and still wonder now why that should be, but there you are.

                        I 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @Igor86
                          Glad that sorted you out. I nearly suggested @pyqtslot but could not see from the description why that would make such an initial difference of several seconds, and still wonder now why that should be, but there you are.

                          I Offline
                          I Offline
                          Igor86
                          wrote on last edited by
                          #12

                          @JonB it looks like the problem is here again. but it was indeed away yesterday when i tested it several times.. the only differenche is that now i have enabled the hard disk lock in windows. so am going to investigate if that makes a difference.

                          JonBJ 1 Reply Last reply
                          0
                          • I Igor86

                            @JonB it looks like the problem is here again. but it was indeed away yesterday when i tested it several times.. the only differenche is that now i have enabled the hard disk lock in windows. so am going to investigate if that makes a difference.

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #13

                            @Igor86
                            Hmmm. I hope @pyqtslot does somehow work for you, just I wonder how it could possibly make a difference of seconds in your situation. I would wonder whether something else might be going on, as you say to do with first time reboot. In your output there is Got Crate ID between the emission and the receipt, so something else is going on in your code other than what you have shown?

                            "between 3 and 6 seconds" is an enormous delay in computer terms. I find it hard to believe that whatever @pyqtslot does it could cost so much without it. If, say, https://stackoverflow.com/a/45842186/489865 or https://stackoverflow.com/a/40330912/489865 or https://www.codeproject.com/Articles/1123088/PyQt-signal-slot-connection-performance are right in their description I can't see how it would achieve that. To me it sounds more like: the slot will only print its output once the processor switches from the worker thread back to the main thread. If something on your system is "very busy" (hardware? memory paging?), first time after reboot, the OS may be unable to do that in a timely manner?

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved