1
如果连接成功,现在它的工作一次,但如果异常满足, 不重试,因为我想,只是抛出:蟒蛇:重试X倍,如果异常满足,退出如果没有
Will retry: [Errno 111] Connection refused
它应返回False如果所有的尝试没有成功,如果至少一个返回答案
似乎有什么东西与复杂的“而”需要,如
for attempt in range(attempts) and while True
这里是我的代码:
attempts = 10
for attempt in range(attempts):
try:
conn = httplib.HTTPConnection("server:80", timeout=5)
conn.request("GET","/url")
r = conn.getresponse()
except socket.error, serr:
print("Will retry: %s" % serr)
conn.close()
else:
print("OK")
finally:
return False
我也试过:
for attempt in range(attempts):
while True:
try:
同样的结果...