<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Jun 5, 2016 at 11:38 AM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
And AFAICT the tornado.gen.with_timeout wrapper doesn't deal with<br>
coroutines/coroutine runners at all? </blockquote><div><br></div><div>It doesn't currently, but this is a bug. It should be creating a coroutine runner for the input task if it is not already a Future. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I just read the source, but I<br>
couldn't fully follow it. If I write<br>
  async def do_stuff():<br>
      try:<br>
          await aiohttp.get("<a href="https://python.org" rel="noreferrer" target="_blank">https://python.org</a>")<br>
      except:<br>
          print("oops, cleaning up")<br>
          raise<br>
      else:<br>
          print("did it!")<br>
  await tornado.gen.with_timeout(timedelta(seconds=0.0001), do_stuff())<br>
and the timeout fires, then is the output "oops, cleaning up", "did<br>
it!", or nothing at all?<br></blockquote><div><br></div><div>This would not produce any output: Tornado doesn't do asyncio-style cancellation (I've had enough bad experiences with KeyboardInterrupt cropping up at unexpected times). The inner task has its own coroutine runner and will continue after the outer task has stopped waiting for it.  This allows the Future from the inner task to be reused (either in the same outer task or in another task), but it does require that some lower-level timeout mechanism also be present to prevent timed-out tasks from accumulating forever. This is not ideal and it would be good to allow the inner task to find out its been canceled (the reusability of Futures only matters in rare cases).</div><div><br></div><div>-Ben</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br></blockquote></div></div></div>