Pause before retry connection in Python
I am trying to connect to a server. Sometimes I cannot reach the server and would like to pause for a few seconds before trying again. How would I implement the pause feature in Python. Here is what I have so far. Thank you. while True: try: response = urllib.request.urlopen(http) except URLError as e: continue break I am using Python 3.2 This will block the thread for 2 seconds before continuing: import time time.sleep(2) In case you want to run lots of these in parallel, it would be much more scalable to use an asynchronous networking framework such as Twisted , where "sleeping" doesn't mean