내가 토네이도와 파이썬에 초보자입니다 요청합니다. 며칠 전 나는 비 차단 나머지 API를 작성하기 시작했지만, 아직 임무를 완수 할 수 없었습니다. 이 끝점 "localhost : 8080/async"에 두 개의 요청을 동시에 보내면 두 번째 요청은 20 초 후에 응답합니다! 그건 내가 뭔가 잘못하고 있다고 설명한다.파이썬 토네이도 gen.coroutine 블록
MAX_WORKERS = 4
class ASYNCHandler(tornado.web.RequestHandler):
executor = ThreadPoolExecutor(max_workers=MAX_WORKERS)
counter = 0
def pow_task(self, x, y):
time.sleep(10)
return pow(x,y)
async def background_task(self):
future = ASYNCHandler.executor.submit(self.pow_task, 2, 3)
return future
@gen.coroutine
def get(self, *args, **kwargs):
future = yield from self.background_task()
response= dumps({"result":future.result()}, default=json_util.default)
print(response)
application = tornado.web.Application([
('/async', ASYNCHandler),
('/sync', SYNCHandler),
], db=db, debug=True)
application.listen(8888)
tornado.ioloop.IOLoop.current().start()