How to make SQLAlchemy in Tornado to be async?

前端 未结 5 433
花落未央
花落未央 2020-12-02 05:11

How to make SQLAlchemy in Tornado to be async ? I found example for MongoDB on async mongo example but I couldn\'t find anything like

5条回答
  •  被撕碎了的回忆
    2020-12-02 05:34

    I am using tornado6 with sqlalchemy in next way:

    from tornado.ioloop import IOLoop
    
    def sql_function():
        pass
    
    class Handler(tornado.web.RequestHandler):
        async def post(self):
            args = get_front_end_args()
            result = await IOLoop.current().run_in_executor(None,sql_function,*(args))
            self.write({"result":result})
    

提交回复
热议问题