Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch PyCharm debugger's "Stop Button"?

Quick Question: What signal/Exception does PyCharm's Stop Button send when debugging a python script?

Background: Several posts document that hitting Ctrl-C doesn't send a Keyboard Interrupt/SIGINT signal to a python script when using PyCharm's Debugger. Fine. My question is, what does get sent to the Python script when clicking the Debugger's "Stop Button". I'd like to re-write my code to catch whatever that signal/Exception is. [I'm using OSX w/PyCharm 4.0.4]

like image 637
Dutch Avatar asked Feb 09 '15 19:02

Dutch


1 Answers

When you stop the process after debugging it, it sends a SIGKILL signal to the interpreter.

Process finished with exit code 137

Exit codes above 128 mean that it's a 128 + a signal's number (in this case, 9, which is a SIGKILL).

You could catch SIGTERM using signal.signal(), but SIGKILL can't be caught. There's nothing you can do with it.
Well, you could set up a separate script that would monitor the first one (checking for its PID existance in the running processes, for example) and do something if the given process is terminated.

like image 51
Igor Hatarist Avatar answered Nov 02 '22 12:11

Igor Hatarist