# Parallel

> par_map and its errors: fork-based CPU parallelism for Python callbacks.

Source: https://docs.pyrula.io/reference/parallel/

Generated from the type stubs and docstrings. Do not edit by hand.

## Types

## `ForkSafetyError`

``par_map`` was called in an unsafe state to ``fork`` (threads alive / nested).

---

## `ParMapError`

Aggregate of element failures from a ``par_map`` call (``on_error="raise"``).

``errors`` is ``list[tuple[int, str]]`` (input index, formatted traceback), sorted
by input index; ``partial`` is the container of successful results (same type as a
normal return), with error slots holding a sentinel (0.0 / 0 / None) - read
``errors`` for which.

```python
ParMapError(message: str, *, errors: Optional[Errors] = None, partial: Optional[ParMapResult] = None)
```

**Fields:**

- `errors`
- `partial: Optional[ParMapResult]`

---

## `RegionOverflowError`

Object-path results overflowed a worker's result region.

```python
RegionOverflowError(message: str, *, errors: Optional[Errors] = None, partial: Optional[ParMapResult] = None)
```

---

## `WorkerDiedError`

A worker exited before completing its chunk (crash, ``os._exit``, signal).

```python
WorkerDiedError(message: str, *, errors: Optional[Errors] = None, partial: Optional[ParMapResult] = None)
```

## Functions

### `par_map`

```python
par_map(fn: Callable[[Any], Any], data: ParMapData, *, workers: Optional[int] = None, chunk_size: Optional[int] = None, timeout: Optional[float] = None, on_error: str = 'raise', result_codec: Any = _UNSET, result_type: Optional[type] = None, region_size: Optional[int] = None, initializer: Optional[Callable[..., Any]] = None, initargs: Sequence[Any] = (), unsafe_allow_threads: bool = False) -> ParMapResult
```

Run ``fn`` over ``data`` across forked worker processes (real parallelism).

``fn`` runs in a forked child process - treat it as pure; mutations to
globals, closures, or shared state are applied in the child and silently
lost. See the docsite for dispatch-by-input-type, ``result_codec``/
``result_type``, RNG/GC caveats, and ``initializer`` details.

Raises ``NotImplementedError`` without ``os.fork`` (e.g. Windows),
``ForkSafetyError`` for a live-thread or nested-worker call, ``ValueError``
for a bad option combination, ``ParMapError`` (or its ``WorkerDiedError``/
``RegionOverflowError`` subclasses) for element failures under
``on_error="raise"``, and ``TimeoutError`` past ``timeout``.
