Ivo Bosticky
Ivo Bosticky

Reputation: 6408

How to suppress the Terminated message when python script receives a SIGTERM

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.

Upvotes: 0

Views: 1201

Answers (1)

ch3ka
ch3ka

Reputation: 12158

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?

Upvotes: 1

Related Questions