Given this simple code where I declare a class and a functions inside it. In the main I try to call the function but the call is not made. I don't get any error but if I put a print in order to know if the call has happened nothing occurs.
models
class Balance(Document):
gross_balance = FloatField(required=True, min_value=0, default=0)
@classmethod
def createBalance(cls, gross_balance):
result = yield Balance.objects.create(gross_balance = gross_balance)
result.save()
@classmethod
def sayHi(cls):
print "Hi there"
main
from models import Balance
class CreateBalanceHandler(tornado.web.RequestHandler):
@tornado.gen.coroutine
def post(self):
gross_balance = self.get_argument('gross_balance')
Balance.createBalance(gross_balance)
Balance.sayHi()
self.redirect('/query/{}'.format(gross_balance))
What am I doing wrong? The sayHi function show its print but there's no reaction with createBalance.
Decorate
createBalancewithgen.coroutineto run it on ioloop. To wait until balance is created invoke it likeyield Balance.createBalance()inRequestHandlermodels
main
Note: As I mentioned in snippet's comment, in motorengine the
Document.savereturnsFutureand probably you want toyieldit as well, to wait until it has finished.