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)

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay