Code: Select all
try:
while True:
time.sleep(1)
pass
except:
#Code that will be executed if the stop button is pressed in Thonny
with open('data.txt', 'w') as f:
f.write("Exception raised")
So I need to know exactly the exception to be able to reset the state of the pins and other external elements like displays, otherwise if a different exception occurs, I will not be able to know its cause.
I should also clarify that in Python, the code inside except is not executed if the stop button is pressed, it only happens in MicroPython.