QtConcurrent in PySide/PyQt

pyqt thread
pyqt update gui from thread
pyqt threadpool
pyqt event loop
pyqt qrunnable
qrunnable vs qthread
pyqt ui is hanging thread runs
pyqt queue

I'm trying to figure out if subclassing QtConcurrent and writing a run method inside it will work:

class Task(QtCore.QtConcurrent):

     def run(self, function):
           function()

Or is it completely useless?

It's completely useless, because QtConcurrent is a namespace, not a class.

Also, neither PyQt nor PySide provide any of the functionality provided by QtConcurrent, because it's all template-based and therefore impossible to wrap.

PS: the PySide documentation you linked to is for the ReduceOption enum. Since it's doubtful whether that enum has any use outside the QtConcurrent namespace, it's probably a bug that PySide includes it.

QtConcurrent — PySide v1.0.7 documentation, The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded programs without using low-level threading See the Qt Concurrent chapter in the threading documentation. Indt Openbossa Qt Python. It's completely useless, because QtConcurrentis a namespace, not a class. Also, neither PyQt nor PySide provide any of the functionality provided by QtConcurrent, because it's all template-based and therefore impossible to wrap. PS: the PySide documentation you linked to is for the ReduceOptionenum.

The class you are looking for is QRunnable.

Multithreading PyQt applications with QThreadPool (Updated 2020 , thanks for your great explanation ,it helped me a lot !!! the GIL is not present under Ironpython nor Jython and so, running multithreaded Python� The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded programs without using low-level threading primitives. See the Qt Concurrent chapter in the threading documentation.

I am stuck on the same problem in PyQt5. I guess the only solution is to do this locally:

def connect(self):
    class ConnectThread(QThread):
        def __init__(self, func):
            super().__init__()
            self.func = func
        def run(self):
            self.func()
    self.connectThread = ConnectThread(self._connect)
    self.connectThread.start()

def _connect(self):
    if self._driver is None:
        uri = self.uriString()
        if uri and self.user and self.password:
            self.statusMessage.emit("Connecting to the Graph Database....", -1, "color:blue;")
            try:
                self._driver = GraphDatabase.driver(uri, auth=(self.user, self.password))
                self.statusMessage.emit("Connected!", 5000, "color:green;")
            except Exception as e:
                self.clearStatusMessage.emit()
                Error(str(e)).exec_()
                if __debug__:
                    raise e

And remember to set the thread to a member variable: self.thread = ... or else your thread reference will go out of scope, and most likely the thread object deleted.

You could also move your function-to-call into a local definition of it as Python allows both nested functions and classes within one another!

[PySide] QtConcurrent support? - Mailing Lists, if he is right(QThread is "real" multithreading in Python),then why > not add QtConcurrent to PyQt ? Because its API is very difficult, if not� PySide (deprecated), PySide2 (Active) is basically the same as PyQt, but with a different license and developed by the QT company, to makes things even less clear it also goes by the name QT for

[PyQt] QtConcurrent support?, This function is a part of the Qt Concurrent framework. Running a Function in a Separate Thread�. To run a function in another thread, use QtConcurrent::run� Detailed Description¶. All other Qt modules rely on this module. To include the definitions of the module’s classes, use the following directive:

Concurrent Run — Qt for Python, Software dev with almost 10 years of work experience, love python, django, smart home, automations, IoT stuff. Currently working full time on� Detailed Description¶. All other Qt modules rely on this module. To include the definitions of the module’s classes, use the following directive:

PyQt: Threading Basics Tutorial, Internally the QtConcurrent module uses the QThreadPool class for Oct 28, 2015 � Python Quick Tip: Simple ThreadPool Parallelism Published Oct 28, 2015 � The event loop is started by calling.exec_ () on your QApplication object and runs within the same thread as your Python code. The thread which runs this event loop — commonly referred to as the GUI thread — also handles all window communication with the host operating system.

Comments
  • Why won't you give it a try?
  • Very interesting. I was just about to experiment a little bit with QtConcurrent in PyQt5 when I realized that I can't find anything. Thanks for the hint. I guess C++ it is. :D
  • That does not provide the ability to call any function I don't think... Only option here is to inherit from QThread. See my solution above.