I am trying to exit the program if a condition has been met. The condition is in a try
block.
Here is my code:
import time
a=1
while True:
time.sleep(2)
try:
if a==1:
print("exiting")
exit(0)
else:
print("in else")
except:
print("in except")
instead of exiting it is printing:
exiting
in except
exiting
in except
exiting
in except
exiting
in except
.
.
.
Any explanation?