Use sys.stdin.isatty() to auto-detect: foreground sessions still respond to SIGHUP (terminal close kills the process as expected), background/piped processes ignore it and survive.
Use sys.stdin.isatty() to auto-detect: foreground sessions still respond to SIGHUP (terminal close kills the process as expected), background/piped processes ignore it and survive.