Cannot catch Ctrl-C gracefully in this script

Linking this related post in case it helps.