Answers for "catch ctrl c in python3"

0

ctrl c exception python

#Try the following:
try:
    # DO THINGS
except KeyboardInterrupt:
    # quit
    sys.exit()
Posted by: Guest on June-08-2021
0

how to catch ctrl c in python

import signal
import time
 
def handler(signum, frame):
    res = input("Ctrl-c was pressed. Do you really want to exit? y/n ")
    if res == 'y':
        exit(1)
 
signal.signal(signal.SIGINT, handler)
 
count = 0
while True:
    print(count)
    count += 1
    time.sleep(0.1)
Posted by: Guest on December-23-2021

Python Answers by Framework

Browse Popular Code Answers by Language