@gen.engine + @web.asynchronous

117 views
Skip to first unread message

Андрей Григорьев

unread,
Jan 23, 2012, 5:20:06 AM1/23/12
to Tornado Mailing List
Hello!

This code is not working:

>>>
# coding: utf-8

from functools import partial

from tornado import web, gen, ioloop


def hello(param, callback):
ioloop.IOLoop.instance().add_callback(partial(callback, param))

class MainHandler(web.RequestHandler):

@gen.engine
@web.asynchronous
def get(self):
res = yield gen.Task(hello, "hello!\n")
raise Exception("Oops!")
self.write(res)
self.finish()


application = web.Application([
(r"/", MainHandler),
], debug=True)

if __name__ == "__main__":
application.listen(8888)
ioloop.IOLoop.instance().start()
>>>

But if you change the order of the gen.engine and the web.asynchronous
decorators, then it works. Checked on latest git version.

> For RequestHandler
> <http://www.tornadoweb.org/documentation/web.html#tornado.web.RequestHandler>
> get/post/etc methods, this means that both the tornado.gen.engine
> <http://www.tornadoweb.org/documentation/gen.html#tornado.gen.engine>
> and tornado.web.asynchronous
> <http://www.tornadoweb.org/documentation/web.html#tornado.web.asynchronous>
> decorators must be used (*in either order*).

May be the gen.engine.__doc__ should be updated? Or is this a bug?

Thanks.

--
Andrew

Ben Darnell

unread,
Jan 23, 2012, 12:47:16 PM1/23/12
to python-...@googlegroups.com
Yes, it looks like the docs are incorrect. I've checked in a fix for
the docs; thanks for reporting this.

-Ben

2012/1/23 Андрей Григорьев <and...@ei-grad.ru>:

Reply all
Reply to author
Forward
0 new messages