DEV Community

Cover image for Suppressing "KeyboardInterrupt" Message on Python Script
Talles L
Talles L

Posted on

Suppressing "KeyboardInterrupt" Message on Python Script

from signal import signal, SIGINT
signal(SIGINT, lambda _, __: exit())

print('No message or stack trace will be printed when you Ctrl+C this program.')

from time import sleep
sleep(999999999)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)