In asyncio, calling a coroutine without scheduling it (using yield from
or otherwise) does not run its code.
According to the asyncio docs:
Calling a coroutine does not start its code running – the coroutine object returned by the call doesn't do anything until you schedule its execution. There are two basic ways to start it running: call
await coroutine
oryield from coroutine
from another coroutine (assuming the other coroutine is already running!), or schedule its execution using theensure_future()
function or theAbstractEventLoop.create_task()
method.
In tornado, calling a coroutine without observing the returned Future
object (using yield
or otherwise) runs it asynchronously (provided that
there's an IOLoop
running) but will not raise any exception. When the
Future
object is garbage collected, a stack trace will be logged.
According to the tornado docs:
When exceptions occur inside a coroutine, the exception information will be stored in the
Future
object. You must examine the result of theFuture
object, or the exception may go unnoticed by your code. This means yielding the function if called from another coroutine, using something likeIOLoop.run_sync
for top-level calls, or passing the Future toIOLoop.add_future
.