Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Can't catch error in gen.Task #405

Closed
perol opened this Issue · 1 comment

3 participants

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

@bdarnell bdarnell closed this issue from a commit
@bdarnell bdarnell Use a StackContext to allow exceptions thrown from asynchronous funct…
…ions

called by a generator to be caught normally.

Closes #405.
Closes #411.
ac9902c
@bdarnell bdarnell closed this in ac9902c
@adamaflynn adamaflynn referenced this issue from a commit in ContextLogic/tornado
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
Something went wrong with that request. Please try again.