-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathctrl_c.py
More file actions
25 lines (20 loc) · 566 Bytes
/
Copy pathctrl_c.py
File metadata and controls
25 lines (20 loc) · 566 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)