spacr.qt.gil_priority

Keep the Qt interface responsive during Python-bound background work.

Python code that does not release the global interpreter lock can delay the GUI thread. claim() temporarily lowers the interpreter thread-switch interval to BUSY_INTERVAL; release() restores the previous value after the last active worker finishes. Prefer the balanced responsive_gui() context manager for pipeline work.

The setting is process-wide, so it is applied only while a Qt worker is active. Importing this module does not change the switch interval and headless runs incur no cost.

Notes

A shorter interval creates more context switches and can make pure-Python workers marginally slower. NumPy and similar compiled operations generally release the interpreter lock and are less affected.

Functions

active(→ bool)

Return whether at least one worker holds a responsiveness claim.

claim(→ None)

Request the responsive-GUI switch interval for one active worker.

release(→ None)

Release one worker's claim and restore the interval when none remain.

responsive_gui()

Apply the responsive-GUI interval for the duration of a context.

Module Contents

spacr.qt.gil_priority.active() → bool[source]

Return whether at least one worker holds a responsiveness claim.

spacr.qt.gil_priority.claim() → None[source]

Request the responsive-GUI switch interval for one active worker.

Calls are reference-counted and thread-safe. Each call should be paired with release(); the original interval is restored only after the final claim is released.

spacr.qt.gil_priority.release() → None[source]

Release one worker’s claim and restore the interval when none remain.

Extra calls after the count reaches zero have no effect.

spacr.qt.gil_priority.responsive_gui()[source]

Apply the responsive-GUI interval for the duration of a context.

The claim is released when the block exits, including when it raises an exception. Nested and concurrent contexts are supported.

Yields:

None – Control returns to the context body while the claim is active.

Nested helpers

_application_event_hub_class._ApplicationEventHub.__init__(self, parent=None) → None

Start with no watchers.

spacr/qt/gil_priority.py:143

_application_event_hub_class._ApplicationEventHub._forget_the_dead(self) → None

Drop every watcher whose object is gone.

A watcher Qt held directly came off the application when its object was destroyed; behind the hub it would stay in the chain, skipped but still looked at on every event of its kinds – one per module screen ever built, for the life of the process.

spacr/qt/gil_priority.py:213

_application_event_hub_class._ApplicationEventHub._rebuild(self) → None

Index the live watchers by event type, newest first.

spacr/qt/gil_priority.py:149

_application_event_hub_class._ApplicationEventHub.add(self, watcher, kinds) → None

Ask watcher first about every event of kinds.

spacr/qt/gil_priority.py:158

_application_event_hub_class._ApplicationEventHub.discard(self, watcher) → bool

Stop asking watcher; True when it was being asked.

spacr/qt/gil_priority.py:165

_application_event_hub_class._ApplicationEventHub.eventFilter(self, watched, event)

Hand event to the watchers that asked for its type.

spacr/qt/gil_priority.py:186

_application_event_hub_class._ApplicationEventHub.watchers(self) → tuple

The live watchers, in the order they are asked.

spacr/qt/gil_priority.py:180