9

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]

Dutch
  • 109
  • 1
  • 5

1 Answers1

6

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.

Igor Hatarist
  • 5,234
  • 2
  • 32
  • 45
  • Thanks for responding. What version of PyCharm are you running? When I run your code using "Run" (or pressing ^R), I do in fact get the KeyboardInterrupt when clicking the "stop process" button. When I run your code using "Debug" (or pressing ^D), I get don't get the KeyboardInterrupt and see only "Process finished with exit code 137" when clicking the "stop process" button. – Dutch Feb 10 '15 at 21:30
  • @Dutch I'm very sorry, I _did_ run it using Run (^R). I have updated my answer. – Igor Hatarist Feb 10 '15 at 21:40
  • Thanks. This is what I was concerned was happening -- a non-catchable signal that I can't (easily) use to trigger the "clean up" part of my code. Thanks for confirming that. – Dutch Feb 12 '15 at 19:40