Skip to content

Instantly share code, notes, and snippets.

@datavikingr
Created January 20, 2023 16:13
Show Gist options
  • Save datavikingr/9eb1c5cf30b5077f78a50ce489f1377d to your computer and use it in GitHub Desktop.
Save datavikingr/9eb1c5cf30b5077f78a50ce489f1377d to your computer and use it in GitHub Desktop.
Python: Try until Success loop
# Dead simple try-until-success blob.
# I do a lot of OCR based web-scraping for work, and waiting on Java frontends to load consistently breaks my automation.
# This bug-fixes the OCR library not finding the object to click, well enough enough to complete the whole pass without restarts.
import time
while True:
    try:
        #some code
    except:
        time.sleep(1)
        continue
    else:
        break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment