ctrl c exception python
#Try the following:
try:
# DO THINGS
except KeyboardInterrupt:
# quit
sys.exit()
ctrl c exception python
#Try the following:
try:
# DO THINGS
except KeyboardInterrupt:
# quit
sys.exit()
how to catch ctrl c in python
import signal
import time
import readchar
def handler(signum, frame):
msg = "Ctrl-c was pressed. Do you really want to exit? y/n "
print(msg, end="", flush=True)
res = readchar.readchar()
if res == 'y':
print("")
exit(1)
else:
print("", end="r", flush=True)
print(" " * len(msg), end="", flush=True) # clear the printed line
print(" ", end="r", flush=True)
signal.signal(signal.SIGINT, handler)
count = 0
while True:
print(f"{count}", end="r", flush=True)
count += 1
time.sleep(0.1)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us