Skip to content
Edit this page

Parallel

Register ParallelServiceProvider for application-owned native executor pools. The default process driver uses spawned Python processes for CPU work. The thread driver runs blocking I/O and copies the caller's context variables. Pools start lazily and close when the application shuts down.

from functools import partial

from titancore.facades import Parallel
from titancore.parallel import ParallelServiceProvider

app.register(ParallelServiceProvider())

# Inside the application's async lifecycle:
results = await Parallel.run({"power": partial(pow, 2, 4)})
threads = await Parallel.driver("thread")
values = await threads.run([partial(pow, 3, 2)])

Configure parallel.driver as process or thread and optionally set parallel.workers to a positive integer. ParallelManager accepts the same settings directly and must be closed with await manager.close() when used outside the application.

Jobs are zero-argument synchronous callbacks. Results preserve sequence order or mapping keys. Process callbacks and results must be picklable: use module-level functions or functools.partial with serializable arguments. Create database connections and other application resources inside each worker. Containers, request identity, and live connections do not cross the process boundary.

Errors propagate to the caller. Cleanup waits for running work and cancels queued work where the native executor permits it. Cancellation cannot stop an already running thread or process callback. This module adds no durable queue or background job scheduler.