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 回答1: This will block the thread for 2 seconds before continuing: import time time.sleep(2) 回答2: In case you want to run lots of these in parallel, it would