concurrency , , -, . , , . , . , :
import time
import requests
def get_content(url, timeout):
resp = requests.get(url, timeout=timeout)
if resp.status_code != 200:
raise LookupError('status is not 200')
return resp.content
timeout = 5 # seconds
retry_interval = 0
max_retry_interval = 120
while True:
try:
response = get_content('https://example.com', timeout=timeout)
retry_interval = 0 # reset retry interval after success
break
except (LookupError, requests.exceptions.Timeout):
retry_interval += 10
if retry_interval > max_retry_interval:
retry_interval = max_retry_interval
time.sleep(retry_interval)
concurrency, Scrapy. Twisted. Scrapy time.sleep
reactor.callLater(fn, *args, **kw)
.