I have a code with a one-liner while and a try-except statement which behaves weirdly.
This prints ‘a’ on Ctrl+C:
try:
while True:
pass
except KeyboardInterrupt:
print("a")
and this too:
try:
i = 0
while True: pass
except KeyboardInterrupt:
print("a")
but this doesn’t, and it throws a traceback:
try:
while True: pass
except KeyboardInterrupt:
print("a")