Skip to content

pygx.concurrent

Concurrent execution under PyGX's contextual overrides.

concurrent

Concurrent execution under PyGX's contextual overrides.

pygx.concurrent provides building blocks for running synchronous and asynchronous Python functions in parallel, with optional retry and progress reporting:

  • with_retry / with_retry_async wrap a callable with bounded retries and optional exponential backoff.
  • execute / execute_async apply a function to an iterable of inputs in parallel and return results in input order.
  • map lazily yields (input, output, error) tuples with support for ordered/unordered output, per-item and overall timeouts, and a thread-safe progress bar.
  • Job, RetryError, and RetryEntry describe a single unit of work and its retry history.
  • ExecutorPool / get_executor cache thread pools keyed by resource id so global rate limits can be honored across nested calls.
  • invoke_async / invoke_sync / iter_sync / sync_context_manager adapt between sync and async callables (built on anyio blocking portals) while propagating contextual overrides across the boundary.
  • thread_local_* helpers manage thread-local state with optional scope-based override semantics.

Contextual overrides registered via pg.contextual.override are propagated into worker threads using pg.contextual.with_override, so symbolic objects that resolve pg.contextual.Placeholder fields behave consistently inside and outside the executor.

The package uses lazy attribute resolution: public symbols are wired through __getattr__ so that submodules like _thread_local can be imported by foundational layers (e.g. pg.utils._formatting) without triggering the heavier _async / _map / _retry imports that depend on pg.utils and pg.symbolic.

options: show_root_heading: false show_root_toc_entry: false members_order: source heading_level: 2