<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jun 3, 2016 at 10:17 PM, Yury Selivanov <span dir="ltr"><<a href="mailto:yselivanov@gmail.com" target="_blank">yselivanov@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[..]<br>
<span class="">> Actually, +1 for Ben’s suggestion to revisit if asyncio.Futures really need call_soon scheduling of callbacks. Specifically, a torrent of call_soon doesn’t really achieve “fair scheduling” as suggested by Yury anyway:<br>
><br>
> <a href="https://gist.github.com/ambv/3324e3e569b9f7883dfcb9c8cb1d5445" rel="noreferrer" target="_blank">https://gist.github.com/ambv/3324e3e569b9f7883dfcb9c8cb1d5445</a><br>
<br>
</span>One quick story about call_soon: while working on uvloop I once spent a couple of hours debugging why asyncio/sslproto.py didn’t work.  Turned out that SSLProtocol, in its connection_made scheduled some callbacks with loop.call_soon; and data_received did that too.  Turned out that libuv called data_received one loop iteration earlier, which resulted in a race condition.  What I’m trying to say here, is that making a subtle difference in how callbacks are scheduled can introduce some hard to debug bugs.<br></blockquote><div><br></div><div>If things are so sensitive to minor changes in timing, doesn't that set the bar impossibly high for interoperability? In Tornado, we have similar concerns around "fair scheduling" of coroutines, but we solved this by using our equivalent of call_soon() in the coroutine runner rather than in the Future itself. So asyncio Futures yielded in a coroutine that uses Tornado's runner will be called one iteration later as they make two trips through the scheduler, while if asyncio.Task gained the ability to understand Tornado Futures they could turn into a busy loop that let nothing else run. If we want interoperability, we're going to have to mandate that code like SSLProtocol be tolerant of changes in timing (of course, saying that is one thing and achieving it is another)</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
In fact, I’m thinking now that Tornado/Twisted should keep their callbacks scheduling logic as is, and asyncio should keep its current implementation.<br></blockquote><div><br></div><div>Yeah, the risks of making any changes in this area outweigh the benefits, since we'll never get all the implementations to schedule things in exactly the same way.</div><div><br></div><div>-Ben</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
Anyways, I’ve tried to update asyncio Future to call callbacks directly:<br>
<a href="https://github.com/1st1/asyncio/commit/9da7ff868f1405893947118178d62bb7e1eb3a51" rel="noreferrer" target="_blank">https://github.com/1st1/asyncio/commit/9da7ff868f1405893947118178d62bb7e1eb3a51</a><br>
<br>
The result is many broken unittests, until... a segfault in test_create_ssl_connection: <a href="https://gist.github.com/1st1/797dd12932bba7b353038fb7a80148ac" rel="noreferrer" target="_blank">https://gist.github.com/1st1/797dd12932bba7b353038fb7a80148ac</a> (I’ll investigate this later).<br>
<br>
I’d be -1 to change callbacks scheduling in 3.5, IMO this has to wait until 3.6 even if we decide this should be done.<br>
<br>
[..]<br>
<span class="">> +1 for replacing isinstance checks with an attribute that Twisted can add to Deferreds.<br>
> +1 for Ben’s suggestion that we should avoid ‘asyncio’ in the name here. __isfuture__?<br>
<br>
</span>Yes, an asyncio-agnostic name would be better.  I like __isfuture__.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
Yury<br>
_______________________________________________<br>
Async-sig mailing list<br>
<a href="mailto:Async-sig@python.org">Async-sig@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/async-sig" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/async-sig</a><br>
Code of Conduct: <a href="https://www.python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">https://www.python.org/psf/codeofconduct/</a></div></div></blockquote></div><br></div></div>