Loky - Robust Process Pool Executor

3.5.6 · active · verified Sun Apr 12

Loky provides a robust, cross-platform, and cross-version implementation of Python's `concurrent.futures.ProcessPoolExecutor`. It enhances multiprocessing by offering reusable executors, transparent `cloudpickle` integration for complex object serialization, and deadlock-free process management, addressing common pitfalls in parallel Python computing. The library is actively maintained, with its current version being 3.5.6. It primarily follows a minor release cadence with bug fixes and improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the two primary ways to use Loky: `get_reusable_executor()` for a managed and persistent pool, and `ProcessPoolExecutor()` for a direct `concurrent.futures`-like experience. The `if __name__ == "__main__":` block is included for robust multiprocessing execution across different operating systems.

import os
from loky import get_reusable_executor

def worker_function(x):
    # Simulate some work
    pid = os.getpid()
    return f"Processed {x} by PID {pid}"

if __name__ == "__main__":
    # Using get_reusable_executor for managed process pool
    with get_reusable_executor(max_workers=2) as executor:
        results = list(executor.map(worker_function, range(5)))
    print(results)

    # Direct ProcessPoolExecutor usage (similar to concurrent.futures)
    from loky import ProcessPoolExecutor
    with ProcessPoolExecutor(max_workers=2) as executor:
        results_direct = list(executor.map(worker_function, range(5, 10)))
    print(results_direct)

view raw JSON →