omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    2
    3
    1349
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • kzh125
      kzh125 last edited by

      import sys
      import re
      import time

      def 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.

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by JonB

        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.

        1 Reply Last reply Reply Quote 3
        • kzh125
          kzh125 last edited by

          thank you!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors