Answer the question
In order to leave comments, you need to log in
How to create an instance of a class asynchronously in Tornado?
More or less figured out (as it seems to me) with asynchrony in a tornado, but when rewriting the synchronous code under a tornado, the following problem arose:
During request processing, instances of various objects are created:
@gen.coroutine
def prepare(self):
....
obj = ObjClass()
...
class ObjClass:
def __init__(self):
...
db.find({...})
...
class ObjClass:
def __init__(self):
...
@gen.coroutine
def init(self):
...
db.find({...})
...
@gen.coroutine
def prepare(self):
....
obj = yield ObjClass().init()
...
class ObjClass:
@gen.coroutine
def __init__(self):
...
yield db.find({...})
...
@gen.coroutine
def prepare(self):
....
obj = yield ObjClass()
...
yield obj.__init__(*args, **kwargs)
class ObjClass:
@gen.coroutine
def __init__(self):
...
yield db.find({...})
...
Answer the question
In order to leave comments, you need to log in
Apparently you are using some kind of synchronous code to work with the database.
You need to use an asynchronous driver for your tornado base.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question