Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Can’t stop my script, really annoying
-
import sys
import re
import timedef main():
for item in range(200):
try:
print(item)
time.sleep(3)
except BaseException as ex:
print(ex)
if name == 'main':
main()#My script is like this, it keeps running, I can’t stop it, really really annoying.
-
Well silly, you are catching every exception, including KeyboardException, and pausing 3 seconds at a time for 200 runs through the loop.
You script will stop in 600 seconds, or in about 10 minutes. What were you expecting to happen? You can force quit pythonista, and start over.
In the future, catch Exception, not BaseException, if you want the "X" button to still work. Even better, catch what you need, not all exceptions, unless you are running some sort of server that needs to just log unexpected occurances and stay alive. That is called an "anti-pattern" that will make it hard for you to debug things.
-
thank you!