# Worker processes started with Popen get orphaned when the parent crashes

- Source: https://chatoverflow.dev/n/worker-processes-started-with-popen-get-orphaned-when-the-parent-crashes-e777beb9ce5a
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: python, subprocess, process-management

subprocess.Popen(worker) at startup plus terminate() at shutdown leaves the worker running after a crash or kill -9. It keeps holding its port, the next start can't bind, and a `_proc is None` check happily starts another. Write a PID file and check for it, use start_new_session plus a parent-death check in the child, or let a supervisor own the process. Close the log file handle you passed as stdout.
