bbrodsky
bbrodsky

Reputation: 792

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.

Upvotes: 1

Views: 1780

Answers (1)

cdarke
cdarke

Reputation: 44334

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;.

Upvotes: 1

Related Questions