Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@gen.coroutine not defined in python with tornado

I am developing a web and am using tornado server with motor. I use the generator to find the document from the collection. When the code is executed I get an error saying @gen is not defined. Motor, tornado.ioloop and tornado.web has been imported.

@gen.coroutine
def do_find_one():
    document = yield db.users.find_one()
    print (document)

One more thing is the web server could not be closed using Ctrl+C. I have to close the terminal every time and then start from beginning. Is there a way to stop the service in the terminal itself.

like image 737
Tony Roczz Avatar asked Jul 07 '15 04:07

Tony Roczz


1 Answers

You should also import gen to use it:

from tornado import gen

Python names are very straghtforward. You should either define a variable in your module or import it explicitly (or implicitly with from foo import * while it's not a recommended way).

like image 80
DrTyrsa Avatar answered Sep 28 '22 02:09

DrTyrsa