小编Mon*_*cka的帖子

达到 max_clients 限制,请求排队龙卷风

我正在使用 python 发送多个 HTTP 请求 .. > 1000 个请求同时被异步触发。但我收到错误:达到 max_clients 限制,请求排队龙卷风,过了一会儿我收到超时错误。

你如何解决这种问题,发送多个http post请求并避免超时?

这是我正在使用的代码:

class AjaxBatchHandler(basehandler.BaseHandler):
    @tornado.gen.coroutine
    def post(self):
        # just respond with a status, no redirect to login
        if not self.get_current_user:
            self.set_status(403)

        batch = json.loads(self.get_argument("actions").encode('utf-8'))

        client = tornado.httpclient.AsyncHTTPClient()

        batch_requests = []
        for item in batch['actions']:
            request = utils.build_request(
                self,
                action=item['action'].replace("{API}", utils.get_api_baseurl()),
                values=item['values'])
            batch_requests.append(client.fetch(request))

        try:
            batch_responses = yield batch_requests

            batch_result = dict(results=[])
            for result in batch_responses:
                batch_result['results'].append(json.loads(result.body))

        except tornado.httpclient.HTTPError as e:
            batch_result = dict(results=[])
            batch_result['results'].append({"Status": 500,
                                        "StatusMsg": e.message, …
Run Code Online (Sandbox Code Playgroud)

python tornado

1
推荐指数
1
解决办法
2218
查看次数

标签 统计

python ×1

tornado ×1