Я использую tornado.httpclient.AsyncHTTPClient
в заголовке моего веб-приложения торнадо.
Вот мой код
class CustomTornadoHandler(tornado.web.RequestHandler):
def set_default_headers(self):
self.set_header("Access-Control-Allow-Origin", "*")
self.set_header("Access-Control-Allow-Headers", "x-requested-with,application/x-www-form-urlencoded")
self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PATCH, DELETE, PUT')
def initialize(self, *args, **kwargs):
self.db_session = db_session()
def on_finish(self):
db_session.remove()
class AdminUploadAlignerParagraphTaskHandler(CustomTornadoHandler):
executor = concurrent.futures.ThreadPoolExecutor()
@run_on_executor
def post(self):
async def f():
http_client = tornado.httpclient.AsyncHTTPClient()
try:
response = await http_client.fetch("http://www.google.com")
except Exception as e:
print("Error: %s" % e)
else:
logging.info(response.body)
...
self.write("")
f()
Я получаю пример в https://www.tornadoweb.org/en/stable/httpclient.html.
Но это не работает:
RuntimeWarning: coroutine 'AdminUploadAlignerParagraphTaskHandler.post.<locals>.f' was never awaited
f()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Что мне делать?