Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Can't catch error in gen.Task #405

Closed
perol opened this Issue Nov 29, 2011 · 1 comment

Comments

Projects
None yet
3 participants

perol commented Nov 29, 2011

from tornado import ioloop
from tornado import gen
io_loop = ioloop.IOLoop.instance()

def async_func(callback):
    #callback(100)
    10/0
    io_loop.add_callback(lambda: callback(100))

@gen.engine
def main():
    try:
        num = yield gen.Task(async_func)
    except Exception as e:
        print e
    else:
        print num
    finally:
        io_loop.stop()

if __name__=='__main__':
    main()
    io_loop.start()

I expect print error, but it exit because the error can't been caught when using gen.Task

Contributor

kachayev commented Dec 5, 2011

@bdarnell bdarnell closed this in ac9902c Jan 2, 2012

@adamaflynn adamaflynn pushed a commit to ContextLogic/tornado that referenced this issue Mar 19, 2013

Adam Flynn Use a StackContext to allow exceptions thrown from asynchronous funct…
…ions

called by a generator to be caught normally.

Closes #405.
Closes #411.

Conflicts:

	tornado/gen.py
	tornado/test/gen_test.py
9aa5301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment