Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PyQt- losing worker object after QThread has started

PyQt- losing worker object after QThread has started

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.9k Views 2 Watching
  • 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.
  • robbiecooperR Offline
    robbiecooperR Offline
    robbiecooper
    wrote on last edited by
    #1

    Hi All

    I have a QThread that I run a QObject worker on. I connect to it like this;

    def startWorker(self):
            
            updateworker = Worker()
        
            updateworker.moveToThread(self.thread)
            updateworker.sendQImages.connect(self.receiveQImages)
            self.sendImagesToWorker.connect(updateworker.processImages)
            self.deleteWorkerObject.connect(updateworker.deleteWorker)
    
            self.thread.start()
    

    I can't seem to communicate with it, at all, once its been started. I have a logger in the worker, which writes to the log on init, but thereafter is silent. Anyone know what could be wrong? I'm checking that the QThread is running before calling signal to communicate with it, and the thread is running.

    kshegunovK jsulmJ 2 Replies Last reply
    0
    • robbiecooperR robbiecooper

      Hi All

      I have a QThread that I run a QObject worker on. I connect to it like this;

      def startWorker(self):
              
              updateworker = Worker()
          
              updateworker.moveToThread(self.thread)
              updateworker.sendQImages.connect(self.receiveQImages)
              self.sendImagesToWorker.connect(updateworker.processImages)
              self.deleteWorkerObject.connect(updateworker.deleteWorker)
      
              self.thread.start()
      

      I can't seem to communicate with it, at all, once its been started. I have a logger in the worker, which writes to the log on init, but thereafter is silent. Anyone know what could be wrong? I'm checking that the QThread is running before calling signal to communicate with it, and the thread is running.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Blocking the event loop?

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • robbiecooperR Offline
        robbiecooperR Offline
        robbiecooper
        wrote on last edited by
        #3

        I've got Py_BEGIN_ALLOW_THREADS within the function that I'm calling, in the worker. But the function isnt actually being called because the logger is supposed to write to the log before that line. How do I know if the QThread is blocking the event loop?

        kshegunovK 1 Reply Last reply
        0
        • robbiecooperR robbiecooper

          I've got Py_BEGIN_ALLOW_THREADS within the function that I'm calling, in the worker. But the function isnt actually being called because the logger is supposed to write to the log before that line. How do I know if the QThread is blocking the event loop?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @robbiecooper said in PyQt- losing worker object after QThread has started:

          How do I know if the QThread is blocking the event loop?

          It's you who may be blocking it, not the QThread class. If you have a long-running loop (like while (true) or equivalent, sorry I don't know Python) then you will never return control to the thread's event loop and you won't be able to get any slots that are invoked through signals from other threads.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • robbiecooperR Offline
            robbiecooperR Offline
            robbiecooper
            wrote on last edited by
            #5

            Ok thanks I'll check. Don't think so but its worth a punt!

            kshegunovK 1 Reply Last reply
            0
            • robbiecooperR robbiecooper

              Ok thanks I'll check. Don't think so but its worth a punt!

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              It may be worth having a look here as well:
              https://forum.qt.io/topic/81501/another-beginner-design-question

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • robbiecooperR robbiecooper

                Hi All

                I have a QThread that I run a QObject worker on. I connect to it like this;

                def startWorker(self):
                        
                        updateworker = Worker()
                    
                        updateworker.moveToThread(self.thread)
                        updateworker.sendQImages.connect(self.receiveQImages)
                        self.sendImagesToWorker.connect(updateworker.processImages)
                        self.deleteWorkerObject.connect(updateworker.deleteWorker)
                
                        self.thread.start()
                

                I can't seem to communicate with it, at all, once its been started. I have a logger in the worker, which writes to the log on init, but thereafter is silent. Anyone know what could be wrong? I'm checking that the QThread is running before calling signal to communicate with it, and the thread is running.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @robbiecooper said in PyQt- losing worker object after QThread has started:

                updateworker

                this updateworker variable is a local variable and is destroyed when startWorker finishes.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                kshegunovK 1 Reply Last reply
                3
                • jsulmJ jsulm

                  @robbiecooper said in PyQt- losing worker object after QThread has started:

                  updateworker

                  this updateworker variable is a local variable and is destroyed when startWorker finishes.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @jsulm said in PyQt- losing worker object after QThread has started:

                  this updateworker variable is a local variable and is destroyed when startWorker finishes.

                  Ah, I though it was something like a heap allocation, well that's what I get for not keeping my hole shut. :)

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • robbiecooperR Offline
                    robbiecooperR Offline
                    robbiecooper
                    wrote on last edited by
                    #9

                    @jsulm Ah yes- makes total sense! Thanks very much!

                    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