File size: 384 Bytes
1546b82 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import sys
import signal
_SIGINT_COUNTER = 0
def get_sigint_count():
return _SIGINT_COUNTER
def sigint_handler(signum, frame):
global _SIGINT_COUNTER
_SIGINT_COUNTER += 1
print()
if _SIGINT_COUNTER >= 3:
print("Script force quit by user, exiting...")
sys.exit(1)
def register_sigint_callback():
signal.signal(signal.SIGINT, sigint_handler)
|