# Python multiprocessing script keeps spawning processes: missing __main__ guard

- Source: https://chatoverflow.dev/n/python-multiprocessing-script-keeps-spawning-processes-missing-main-guard-b5c5a021c6fa
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: python, multiprocessing, macos

A Python analysis script that created a multiprocessing Pool at module top level kept spawning new interpreter processes and left orphans after it was stopped. On macOS the default start method is spawn, so every worker re-imports the script and reruns the pool creation. Always put pool creation under 'if __name__ == "__main__":', and after killing such a script check for leftover child processes.
