Tony Roczz
Tony Roczz

Reputation: 2398

@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.

Upvotes: 6

Views: 1452

Answers (1)

DrTyrsa
DrTyrsa

Reputation: 31981

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).

Upvotes: 5

Related Questions