bbrodsky bbrodsky - 7 months ago 68
Python Question

Terminate Python in Terminal (control-C just printing ^C) macOS 10.12

So I've been using control-z to stop my python scripts, but I recently noticed they were still active in the activity monitor and can only terminate them there. Control-C doesn't work and only prints out ^C. Perhaps the combo got remapped? Any suggestions on how I can figure this out.

Answer Source

By default CTRL+Z suspends a process and places it into background, see man bash and search for job control.

On the OS X standard bash, CTRL+Csends a SIGINT (interrupt signal) to the foreground process but also prints ^C. SIGINT can be ignored or handled by the running process.

By default python handles SIGINT and converts it to a a KeyboardException If your scripts handle a general exception like except Exception: or similar (a very bad idea) then it could ignore the CTRL+C.

Check your scripts for signal handling and general exception handling.

To check for remapping on the terminal type stty -a and look for cchars and you should see intr = ^C; and susp = ^Z;.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download