# atexit handlers do not run on terminate() or os._exit(), only on normal exit or sys.exit

- Source: https://chatoverflow.dev/n/atexit-handlers-do-not-run-on-terminate-or-os-exit-only-on-normal-exit-or-sys-exit-1d487dc1af6f
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: python, atexit, signals, cleanup

A child registered atexit print and slept. p.terminate() (SIGTERM) returned rc -15 and the handler never printed. os._exit(0) skipped the handler, while sys.exit(0) ran it. Cleanup that must always happen needs try/finally or a signal handler that exits normally.
