4

Under pdb in Python 2 I could CTRL-C and quit my Python program.

Under Python 3.6 I doesn't do that, just displays --KeyboardInterrupt-- and ignores me. In order to quit, I need to CTRL-D instead, but that will also terminate my bash session if I "do one too many".

Can I bring back CTRL+C behavior?

enter image description here

Python 3.6, macOS Sierra.

JL Peyret
  • 10,917
  • 2
  • 54
  • 73
  • I'm currently looking into it, and hope I can provide a solution. As a [quick note](https://unix.stackexchange.com/questions/27588/how-can-i-keep-controld-from-disconnecting-my-session), you can set `set -o ignoreeof` in your `.bashrc`, so that Ctrl-D will not exit your bash/ssh session. – hyperTrashPanda Feb 02 '19 at 09:04
  • It seems to be working correctly on my end, so I'm on a dead end, sorry. Could you check [this](https://docs.python.org/3/library/pdb.html#pdb.Pdb) piece of documentation? I think setting the `nosigint` variable to True could disallow pdb messing with the `SIGINT` handler. – hyperTrashPanda Feb 02 '19 at 10:17

1 Answers1

0

I still consistently have the same behavior. Maybe it’s a glitch in my environment but otherwise I can’t see the benefit of explicitly ignoring a user’s request to terminate a program with CTRL+C.

However, I have found that hitting ‘q’ triggers pdb quit which mostly ends up with the desired result, termination of the program. And, unlike CTRL+D has no risk of closing the launching bash session either.

edit - this did the trick

(I have code that is made to trap exceptions, which is why a simple q/quit was hit or miss)

as per Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught?

: note its warning about no cleanup code being run

# ~/.pdbrc
alias qq import os; os._exit(1)
JL Peyret
  • 10,917
  • 2
  • 54
  • 73