Choose a Process Start Method Explicitly
Core idea
Multiprocessing supports spawn (a fresh interpreter), fork (a copy of the parent process on POSIX), and forkserver (a dedicated server forks children on supported POSIX platforms). In Python 3.13 defaults vary: Windows and macOS use spawn; most other POSIX systems use fork. In 3.14 fork is no longer the default anywhere. Use get_context and a main guard to avoid depending on defaults. Save process examples as scripts, not REPL input.
import multiprocessing as mpprint('spawn' in mp.get_all_start_methods())ctx = mp.get_context('spawn')print(ctx.get_start_method())On supported desktop Python platforms spawn is available; this chooses it without changing the global default.
Expected output:
TruespawnStart an importable worker
import multiprocessing as mpdef greet(code): print('worker', code)if __name__ == '__main__': ctx = mp.get_context('spawn') p = ctx.Process(target=greet, args=(8,)) p.start() p.join() print(p.exitcode) p.close()The main guard prevents recursive spawning when the child imports the script.
Expected output:
worker 80Common mistake
Forking a multithreaded parent is problematic. Do not assume arbitrary inherited state is available in a spawned child; use top-level worker functions and explicit serializable arguments.
Practice
Save the example as a script and run it. Inspect available start methods on your platform and compare with the documented 3.13 and 3.14 defaults.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Process start methods
Check your understanding of process start methods.
What is printed?
import multiprocessing as mpprint(mp.get_context('spawn').get_start_method())What is printed?
import multiprocessing as mpprint(type(mp.get_all_start_methods()).__name__)Why guard process creation with __main__?
Which start method creates a fresh interpreter?