This behavior is due to how signals are handled when Python is launched from a shell script with &
. When Python is launched directly or through noproblem.sh
, the default signal handler for SIGINT
is used, which raises KeyboardInterrupt
. However, when launched through problem.sh
, the signal handler is set to SIG_IGN
, causing SIGINT
to be ignored. This behavior is not explicitly documented, but it's related to how the shell handles signals when running Python as a background process.