1
我使用httpclient.HTTPRequest库发送异步请求,但需要在请求之间添加延迟。 这意味着可以说我配置RPS(请求每秒)= 5。然后我发送一个请求每个0.2但异步。如何在不等待每个请求响应的情况下异步发送请求。延迟HTTP客户端异步调用
这是我的代码:
def process_campaign(self, campaign_instance):
ioloop.IOLoop.current().run_sync(lambda: start_campaign(campaign_instance))
@gen.coroutine
def start_campaign(campaign_instance):
...
while True:
try:
log.info("start_campaign() Requests in Queue: {}".format(len(web_requests)))
web_request = web_requests.pop()
time.sleep(delay)
headers = {'Content-Type': 'application/json'}
request = httpclient.HTTPRequest(auth_username=settings.api_account,
auth_password=settings.api_password,
url=settings.api_url,
body=json.dumps(web_request),
headers=headers,
request_timeout=15,
method="POST")
response = yield http_client.fetch(request)
except httpclient.HTTPError, e:
log.exception("start_campaign() " + str(e))
except IndexError:
log.info('start_campaign() Campaign web requests completed. Errors {}'.format(api_errors))
break
但似乎等待在继续之前的HTTP响应。
如何处理在这种新的生活方式我的错误? – californian