Description: Only use multiprocessing backend in examples when start method is fork
 In Python 3.14+, multiprocessing defaults to the forkserver start method on
 POSIX. When using the multiprocessing backend on top-level functions without
 the fork start method, worker processes cannot deserialize the functions.
Author: Maximiliano Curia <maxy@debian.org>
Bug-Debian: https://bugs.debian.org/1146528
Bug-Debian: https://bugs.debian.org/1141207
Forwarded: no
Last-Update: 2026-11-06
Index: joblib/examples/parallel_random_state.py
===================================================================
--- joblib.orig/examples/parallel_random_state.py
+++ joblib/examples/parallel_random_state.py
@@ -87,7 +87,7 @@ print_vector(random_vector, backend)
 
 import multiprocessing as mp
 
-if mp.get_start_method() != "spawn":
+if mp.get_start_method() == "fork":
     backend = "multiprocessing"
     random_vector = Parallel(n_jobs=2, backend=backend)(
         delayed(stochastic_function)(10) for _ in range(n_vectors)
@@ -115,7 +115,7 @@ def stochastic_function_seeded(max_value
 # reset this seed by passing ``None`` at every function call. In this case, we
 # see that the generated vectors are all different.
 
-if mp.get_start_method() != "spawn":
+if mp.get_start_method() == "fork":
     random_vector = Parallel(n_jobs=2, backend=backend)(
         delayed(stochastic_function_seeded)(10, None) for _ in range(n_vectors)
     )
@@ -133,7 +133,7 @@ if mp.get_start_method() != "spawn":
 #
 # .. [1]  https://numpy.org/doc/stable/reference/random/parallel.html
 
-if mp.get_start_method() != "spawn":
+if mp.get_start_method() == "fork":
     seed = 42
     random_vector = Parallel(n_jobs=2, backend=backend)(
         delayed(stochastic_function_seeded)(10, [i, seed]) for i in range(n_vectors)
Index: joblib/examples/serialization_and_wrappers.py
===================================================================
--- joblib.orig/examples/serialization_and_wrappers.py
+++ joblib/examples/serialization_and_wrappers.py
@@ -68,7 +68,7 @@ print(
 
 import multiprocessing as mp
 
-if mp.get_start_method() != "spawn":
+if mp.get_start_method() == "fork":
 
     def func_async(i, *args):
         return 2 * i
