Skip to content

Commit

Permalink
Changed 'return' to 'raise gen.Return()' to fix Issue tornadoweb#1292,…
Browse files Browse the repository at this point in the history
… explanation added.
  • Loading branch information
arihantagarwal committed Jan 10, 2015
1 parent 32e82f8 commit e10e16f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/guide/async.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ the original synchronous version::
def fetch_coroutine(url):
http_client = AsyncHTTPClient()
response = yield http_client.fetch(url)
return response.body
raise gen.Return(response.body)

The statement ``raise gen.Return(response.body)`` is an artifact of Python 2, in which generators aren't allowed to return values. To overcome this, Tornado coroutines raise a special kind of exception called a ``Return``. The coroutine catches this exception and treats it like a returned value. In Python 3, a ``return response.body`` achieves the same result.

0 comments on commit e10e16f

Please sign in to comment.