Skip to main content

Pqthreads

Pqthreads exposes class interfaces from the main GUI Thread in another QThread in Qt for Python (PySide). In doing so, it facilitates communication between the main (GUI) thread and a dedicated QThreads as offered by Qt for Python.

Installation

Pqthreads comes as a package in the Python Package Index (PyPi) and can be installed using pip:

pip install pqthreads

Usage

In order to use pqhreads, you'll first need a GUI implementation (in Qt for Python (PySide)) whose interface you'd like to expose. Then you need to have a corresponding class that exposes (chosen) methods and attributes in another thread.

GUI implementation

The GUI implementation would be a class that derives from QWidget, e.g. QMainWindow. A very basic example class called FigureWindow can be found in window.py.

Worker class

In a class that inherits from containers.WorkerItem you then choose which methods and attributes are exposed. An examples of this is the class FigureWorker as found in worker.py.

Putting it all together

Using the GUI implementation FigureWindow and worker class FigureWorker the utilities from decorator.py can be used to create a custom decorator:

from pqthreads import decorator

DecoratorCore = decorator.DecoratorCore
DecoratorCore.add_agent('figure', window.FigureWindow, FigureWorker)
decorator_example = decorator.Decorator(DecoratorCore)

Any decorated function will run in the worker thread, while all GUI elements run in the (main) GUI thread.

To simplify access to worker class interfaces, a helper function is useful. This also illustrates how to create and access new GUI elements:

from pqthreads import refs

def figure(*args, **kwargs):
    """ Create, raise or modify FigureWorker objects """
    container = refs.worker.get('figure')
    if not args:
        return container.create(**kwargs)
    figure_worker = args[0]
    container.current = figure_worker
    return figure_worker

This can finally be used to to expose GUI implementation in an existing python program that will run in another worker thread.

from pqthreads.examples import worker

@decorator_example
def main():
    fig = worker.figure(title='Initial title')
    fig.change_title(title='Another title')
    fig.close()

Pittfalls

As illustrated in the previous section, worker class interfaces are accessed through the so-called worker references (as is provided in the module refs). All interfaces are provided as weak references. As soon as the decorated function is exited, the weak references will invalidate and can't be used anymore. Therefore, it's recommended to decorate the function that encapsulates the whole python program in question. This assures that different parts of your own program run in different threads.

The module refs also comes with an object called gui references that stores weak references to the GUI objects. These also will invalidate when the decorated function is exited.

Finally, one should not access the worker references from the (main) GUI thread and also not access gui references from the worker thread. This can lead to trace errors and all sorts of undefined behavior. You have been warned!

Design

Pqthreads separates the GUI elements from all programming elements in QThreads. Since Qt demands that the main thread is used for GUI elements, all other programming functionalities are moved into a dedicated QThread. This shall be called the worker threads.

The following schematic depicts this design.

Pqthreads design

Communication between the GUI and worker threads is solely done using Signal/Slot connections. This is facilitated by the GUIAgents and WorkerAgents.

The interface of a GUI Object is exposed by means of a Worker Object in the Worker Thread.

It is possible expose the interface of multiple types of GUI Objects (in the shown schematic FigureWindow and GraphWindow), which requires multiple Worker- and GUIAgents. These are held the GUIAgency and WorkerAgency respectively.

For each type of GUI/Worker object pair, it's also possible to instantiate multiple objects (of the same type). GUI and Worker objects are held in the GUIItemContainer and WorkerItemContainer respectively.

Pre-commit hooks

This repository comes with pre-commit hooks, which are stored in .hooks. To enable the hooks issue:

git config --local core.hooksPath .hooks/

License

An MIT style license applies for pqthreads, see the LICENSE file for more details.

Metadata

Release files for pqthreads 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pqthreads 0.6.1
File Size Uploaded Provenance Actions
pqthreads-0.6.1.tar.gz 14.6 kB With provenance Details for pqthreads-0.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pqthreads 0.6.1
File Interpreter ABI Platform Actions
pqthreads-0.6.1-py3-none-any.whl Python 3 none any Details for pqthreads-0.6.1-py3-none-any.whl

Total release size: 30.5 kB

Release files / pqthreads-0.6.1.tar.gz

Download URL pqthreads-0.6.1.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2f77dd47b94ce0a1bdefcf61164e49a29f977582c319ef2c805ddab5c520dc82
BLAKE2b-256 checksum
How to use checksums
241e70539f1d3f54c32c4a34cadc764a7adc2f986234a0195c703e9e9a8acde7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 20, 2026.

Transparency log

Release files / pqthreads-0.6.1-py3-none-any.whl

Download URL pqthreads-0.6.1-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b17bb339faa635e19cebf15c75dc2d2bbeab39006e69ec8368b0534cbc08e72f
BLAKE2b-256 checksum
How to use checksums
5564113ce954661db14d1b7ca043ec49413b9aaadce73b44e29902080b7359ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 20, 2026.

Transparency log

Security for pqthreads 0.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pqthreads-0.6.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page