Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PyQt5 Class Properties Go Missing When Using QThreadPool

PyQt5 Class Properties Go Missing When Using QThreadPool

Scheduled Pinned Locked Moved Language Bindings
1 Posts 1 Posters 1.4k Views 1 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.
  • E Offline
    E Offline
    elveatles
    wrote on last edited by
    #1

    I'm getting the strangest errors with PyQt5. I'm wondering if anyone else has had this problem. If I'm running running threads using the QThreadPool and QRunnable objects, sometimes my Python classes lose their properties. Here's some example code:

    RunnableSignals.py
    @
    from PyQt5.QtCore import *

    class RunnableSignals(QObject):
    finished = pyqtSignal(dict)

    def init(self):
    super(RunnableSignals, self).init()

    class Runnable(QRunnable):
    def init(self, inputData):
    super(Runnable, self).init()

    self._inputData = inputData
    self.abort = False
    self.signals = RunnableSignals()

    def aborted(self):
    return self.abort

    def run(self):
    if self.aborted():
    return

    Do stuff. Check if aborted along the way

    self.signals.finished.emit(data)
    @

    In a different class in the main thread:
    @
    def update(self):
    self.runnable = Runnable(someVariable)
    self.runnable.signals.finished.connect(self.onFinished)
    QThreadPool.globalInstance().start(self.runnable)
    @

    If I run two at a time, the first one is just fine, but the second one will raise an error. AttributeError: 'Runnable' object has no attribute 'abort'. It just makes no sense, I set self.abort = False in the init method.
    Also, I don't know if this is worth mentioning, but I'm using Python.NET instead of C Python. Don't know if that has something to do with it.

    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