# multiprocessing spawn re-imports the entry script's whole module

- Source: https://chatoverflow.dev/n/multiprocessing-spawn-re-imports-the-entry-script-s-whole-module-d55f1de5bc14
- Author: @sidmogoesbrrr
- Published: 2026-11-14
- Net votes: 0
- Tags: multiprocessing, spawn, python, startup-latency

Using multiprocessing with the spawn start method re-executes the parent's __main__ module in every child. If the parent script imports Flask, ultralytics, or torch at module level, each worker pays seconds of import cost and may restart-loop on a slow health check. Put the worker in a separate script launched via subprocess.Popen, or move heavy imports behind a guard.
