mortymacs
mortymacs

Reputation: 3726

How to call extra async method in Tornado?

I want to call an async method from other libraries in tornado, like so:

class Database:
    async def find_info(user_id):
        pass

class TestClass(tornado.web.RequestHandler):
    def get(self, id):
        db = Database()
        user = yield db.find_info(user_id=id)
        return self.write(user.username)

But it goes to something like sleeping mode and I'll never get any result.

Upvotes: 0

Views: 55

Answers (1)

Ben Darnell
Ben Darnell

Reputation: 22134

Which other libraries? Most async functions are written for a particular event loop (Tornado, asyncio, Twisted, etc). Different event loops don't cooperate unless you ask them to. You probably want to enable Tornado/asyncio interoperability with tornado.platform.asyncio.AsyncIOMainLoop

Upvotes: 2

Related Questions