Skip to main content

Provides tools for multiprocessing.

Project description

procnexus

Provides tools for multiprocessing.

procnexus offers a tiny, explicit interface for collecting function calls and executing them concurrently with Python's multiprocessing.Pool.

🛠️ Installation

$ pip install procnexus

✨ Features

  • Simple task submission (submit) API.
  • Batch execution with process pools.
  • Asynchronous execution with start(), join(), and get()
  • Ordered results (same order as submitted tasks).
  • Lightweight wrapper around the standard library.

🚀 Quick Start

from procnexus import nexus


def add(a: int, b: int) -> int:
    return a + b


job = nexus(add, processes=4)
job.submit(1, 2)
job.submit(10, 5)
job.submit(-1, 8)

results = job.run()
print(results)  # [3, 15, 7]

# Or start the work asynchronously and collect it later.
job = nexus(add, processes=4)
job.submit(1, 2)
job.submit(10, 5)
job.start()
# Do other work here, and optionally submit more tasks before joining.
job.submit(-1, 8)
job.join()
results = job.get()
print(results)  # [3, 15, 7]

🧩 API

nexus(func, processes=-1) -> ProcNexus

Create a ProcNexus runner from a callable.

  • func: target function for each task.
  • processes: worker-process setting.
    • < 0: use os.cpu_count().
    • = 0: do not create a process pool; run with normal in-process mapping.
    • > 0: pass directly to multiprocessing.Pool.

ProcNexus.submit(*args, **kwargs) -> None

Queue one invocation of func. Before start(), the invocation is stored for later execution. After start() and before join(), the invocation is scheduled immediately and is included in the ordered get() result.

ProcNexus.start() -> None

Start executing all queued tasks. With processes=0, this computes immediately in the current process; otherwise it starts a process pool asynchronously.

ProcNexus.join() -> None

Wait for a previously started run to finish. Results are stored on the runner instead of being returned directly.

ProcNexus.get() -> list

Return results in submission order, including tasks submitted after start(). If the runner is still active, get() waits for it to finish before returning.

ProcNexus.run() -> list

Execute all currently queued tasks in parallel and return results in submission order. This one-shot convenience method leaves the runner in the pending state and keeps submitted tasks queued, so it can be called repeatedly before start().

📝 Notes

  • The submitted callable should be picklable by multiprocessing.
  • Arguments must also be serializable for inter-process communication.
  • Exceptions from worker processes propagate when calling join(), get(), or run().

🔗 See Also

Github repository

PyPI project

⚖️ License

This project falls under the BSD 3-Clause License.

🕒 History

v0.0.2

  • Made run() a non-mutating convenience API to better align with Python conventions: it returns results without implicitly advancing the asynchronous start()/join() lifecycle or consuming queued tasks.
  • Updated process-pool run() execution to use multiprocessing.Pool.starmap, preserving ordered results and keyword-argument handling while keeping queued tasks available for a later async run.
  • Added unit coverage for repeated run() calls, process-pool execution, keyword arguments, and rejecting run() after start().

v0.0.1

  • Added asynchronous execution with start(), join(), and get(), while keeping run() as the one-shot convenience API.
  • Allowed submit() calls after start() and before join(), preserving submission-order results across queued and late-submitted tasks.
  • Expanded README/API documentation and added unit coverage for async lifecycle, ordered results, and invalid state transitions.

v0.0.0

  • Initial release.

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

procnexus-0.0.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

procnexus-0.0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file procnexus-0.0.2.tar.gz.

File metadata

  • Download URL: procnexus-0.0.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for procnexus-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e44f168acce5cbe197537702a60fb0051e6f83e776f164bfac8cd72059b3da78
MD5 c168fbbfbae6885d32ef4390ae05d46e
BLAKE2b-256 73cc589ed9464ac2532ce92894b90f6d5329cb5ee52a688a4807d6338ddb85a7

See more details on using hashes here.

File details

Details for the file procnexus-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: procnexus-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for procnexus-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 97ced8c512f6d5010ffb685c6b3726f9f98ba2d03a6d8d8bcac50d9cb34ce829
MD5 ea3a5e4a6145ae1e7130a0e7a840c333
BLAKE2b-256 d29de71219986033b8a028f3997867fa48c56c704a54a91667572bfb9fa0183f

See more details on using hashes here.

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