0

Is it possible to suppress the "Terminated" message that is printed on stderr when the python interpreter receives a SIGTERM signal. I would like it to terminate silently.

I have tried using a different signal, such as SIGINT, but in this cases python prints out the running scripts Traceback and a "KeyboardInterrupt" message.

Ivo Bosticky
  • 6,338
  • 6
  • 34
  • 35

1 Answers1

1

The "Terminated" is printed by your shell, consult the manual for your shell to find out how to disable it. As for SIGINT, you can actually catch this! To avoid printing the Traceback, simply wrap your whole program in

try:
    do_stuff()
except KeyboardInterrupt:
    pass

or register a Signal handler, as shown here: How do I capture SIGINT in Python?

Community
  • 1
  • 1
ch3ka
  • 11,792
  • 4
  • 31
  • 28
  • Any idea how to stop bash from print out the Terminated message? A similar question on here states that it can't be done, the best you can do is redirect stderr to /dev/null which is not really a solution for me because I still need the stderr output. – Ivo Bosticky Apr 30 '12 at 13:24