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.

2
  • Have you looked at the signals module? Commented Apr 30, 2012 at 12:48
  • Yes, my solution was to install my own signal handler and exit from there. The shell no longer printed out the Terminated message. Commented Apr 30, 2012 at 13:22

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.