16

I kill Python processes with SIGQUIT by pressing Ctrl\ sometimes (usually my own that are misbehaving). Can I prevent the "Python quit unexpectedly" message? I know I can just hit escape, so it's not so bad.

"Python quit unexpectedly." dialog

  • 1
    Why don't you use control-C instead? SIGTERM doesn't cause the message. – ughoavgfhw Oct 21 '13 at 2:38
  • @ughoavgfhw I'm working on a REPL which sometimes puts the terminal in raw mode, so my program receives the ctrl-c as a keystroke instead. Also sometimes I have thread problems, such that threads that should have die don't, and in Python ctrl-c seems only to kill the main thread. (I know I should be using t.daemon = True on these, and I am for the most part) For various reasons, sometimes I need to use ctrl-\. – Thomas Oct 21 '13 at 2:53
  • If it is your code then a development issue your code has to deal with signals – Mark Aug 3 '14 at 21:55
  • @Mark Agreed - this was a problem while I didn't yet have that behavior working in certain edge cases. – Thomas Aug 4 '14 at 11:56
16

If you never want to see the crash report dialogs, there is a preference to disable them:

defaults write com.apple.CrashReporter DialogType none

Log out and back in to apply the changes.

  • 2
    Log out wasn't required in my case. – Cory Klein Jan 30 '14 at 13:03
  • 6
    Is there a way to do the defaults write com.apple.CrashReporter DialogType none selectively for one particular app only? – SexyBeast Dec 29 '15 at 20:49
8

You can also make the message appear as a notification instead:

defaults write com.apple.CrashReporter UseUNC 1
  • 2
    Like this one. On macOS Sierra a notification banner slides over at the top right of the screen and will disappear on its own but if you click it you get the original full crash dump window. So this is perfect. Much less obtrusive but leaves options open. – clearlight Feb 4 '17 at 8:38
3

The default behavior when receiving SIGQUIT is to dump core and exit; the crash reporter is triggered as a part of this process.

Starting with 10.5(?) simply setting a signal handler for SIGQUIT should be sufficient to avoid the crash reporter; you will probably want the handler to also call exit.

import signal, sys, os

def sigquit_handler(signum, frame):
    print 'SIGQUIT received; exiting'
    sys.exit(os.EX_SOFTWARE)

signal.signal(signal.SIGQUIT, sigquit_handler)

# Do your normal work instead of this
print 'Waiting for a signal...'
signal.pause()

The above code was tested on 10.8.5 against /usr/bin/python which is 2.7.2.

  • 1
    Is there a way to do the defaults write com.apple.CrashReporter DialogType none selectively for one particular app only? – SexyBeast Dec 29 '15 at 20:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .