Skip to main content

Utilities for managing threads and processes in a structured way

Project description

Concurrency Group

A library for managing threads and processes in a structured way. It provides the ConcurrencyGroup class which helps avoid accidentally leaking threads and processes, and helps shut them down gracefully.

Key Features

  • Track threads and processes created within a context manager
  • Ensure proper cleanup and failure handling
  • Support nested concurrency groups
  • Propagate shutdown events to all threads and processes
  • Detect and report timeouts and failures

Basic Usage

from imbue.concurrency_group.concurrency_group import ConcurrencyGroup

with ConcurrencyGroup(name="main") as cg:
    # Start a thread
    thread = cg.start_new_thread(target=my_function)

    # Run a process in the background
    process = cg.run_process_in_background(["echo", "hello"])

    # Run a process to completion
    result = cg.run_process_to_completion(["ls", "-la"])

# All threads and processes are automatically waited for on exit

Nested Groups

with ConcurrencyGroup(name="outer") as outer_cg:
    with outer_cg.make_concurrency_group(name="inner") as inner_cg:
        inner_cg.start_new_thread(target=my_function)

Shutdown Support

with ConcurrencyGroup(name="main") as cg:
    thread = cg.start_new_thread(target=my_function)
    # Trigger shutdown of all strands
    cg.shutdown()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

concurrency_group-0.1.7.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

concurrency_group-0.1.7-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file concurrency_group-0.1.7.tar.gz.

File metadata

  • Download URL: concurrency_group-0.1.7.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for concurrency_group-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b2c10482b02d764e8b71b1ebbcae1a3e6438081d51cb09738c8f7f8144c4e784
MD5 7a8682233422b8d9b3b0245ccc51b564
BLAKE2b-256 0be6dd1a94fc94201420f6e6f48bd39c06bcf2a7644533cbe491c6a78f56e35e

See more details on using hashes here.

Provenance

The following attestation bundles were made for concurrency_group-0.1.7.tar.gz:

Publisher: publish.yml on imbue-ai/mng

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file concurrency_group-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for concurrency_group-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 03a3a223d1cee8edc8fd28689c686ac36e0632bc5d6de1acbf853a527f0fb400
MD5 8fbc4be8a8d9b32d78f7603bbe99b28a
BLAKE2b-256 1f0ba10922f066f4bc2b5a4b93c4cfa3469bac031015a53d78d3b947760ee84d

See more details on using hashes here.

Provenance

The following attestation bundles were made for concurrency_group-0.1.7-py3-none-any.whl:

Publisher: publish.yml on imbue-ai/mng

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page