stouputils.ctx.set_mp_start_method module#

class SetMPStartMethod(start_method: str | None)[source]#

Bases: AbstractBothContextManager[SetMPStartMethod]

Context manager to temporarily set multiprocessing start method.

This context manager allows you to temporarily change the multiprocessing start method and automatically restores the original method when exiting the context.

Parameters:

start_method (str) – The start method to use: “spawn”, “fork”, or “forkserver”

Examples

> import multiprocessing as mp
> import stouputils as stp
> # Temporarily use spawn method
> with stp.SetMPStartMethod("spawn"):
> ...     # Your multiprocessing code here
> ...     pass

> # Original method is automatically restored
start_method: str | None#

The start method to use

old_method: str | None#

The original start method to restore

_abc_impl = <_abc._abc_data object>#