<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 6, 2016, at 08:29, Guido van Rossum <<a href="mailto:guido@python.org" class="">guido@python.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On Sun, Jun 5, 2016 at 10:16 PM, Glyph <<a href="mailto:glyph@twistedmatrix.com" class="">glyph@twistedmatrix.com</a>> wrote:<br class=""><blockquote type="cite" class=""><br class="">On Jun 4, 2016, at 13:25, Ben Darnell <<a href="mailto:ben@bendarnell.com" class="">ben@bendarnell.com</a>> wrote:<br class=""><br class="">If things are so sensitive to minor changes in timing, doesn't that set the<br class="">bar impossibly high for interoperability?<br class=""><br class=""><br class="">The sensitivity is not to changes in timing - i.e. when the wall-clock runs,<br class="">or ordering of non-deterministically ordered events - but rather to<br class="">reentrancy - whether certain things complete synchronously while the caller<br class="">is still on the stack and can depend on them having done so upon return.<br class=""><br class="">The recommended way of writing tests within Twisted these days depends<br class="">heavily on `.callback´ synchronously resolving a Deferred, which is what<br class="">adding a call_soon breaks.<br class=""></blockquote><br class="">That's interesting, and also potentially worrisome (for interop, I'm<br class="">not saying Twisted is wrong here).<br class=""><br class="">I think asyncio depends on the opposite: that if you add a callback to<br class="">a Future that's ready it does *not* immediately run. Asyncio's promise<br class="">is pretty strongly that callbacks are serialized (no callbacks running<br class="">inside other callbacks). IIRC we experimented with other semantics and<br class="">found that it was harder to reason about. (IMO if you *know* a Future<br class="">is ready why add a callback to it rather than just calling the damn<br class="">thing if that's what you want?)</div></div></blockquote><br class=""></div><div>I don't think Twisted is necessarily <i class="">right</i> here either.  You're absolutely right that it's easier to reason about reentrancy in some cases if you have a might-be-fired-might-not Future vs. the same sort of Deferred.  I like the property where you can do:</div><div><br class=""></div><div>def test(test_case):</div><div>    a = asynchronously_something()</div><div>    test_case.this_must_not_have_a_result(a)</div><div>    cause_a_to_fire()</div><div>    test_case.assertEqual(test_case.this_must_have_a_result(a), something)</div><div><br class=""></div><div>but this is (somewhat) opposed to the fact that call_soon means you never get the nasty surprise where the callback added in the middle of a function gets run before the rest of it does.  So I think there are good properties in both cases and given some thought it is probably possible to map between them, but Deferred is lower-level here in the sense that it provides a way to do this both with the event loop and without.  You can always call_soon(deferred.callback) but you can't go the other way and force a Future to resolve synchronously - right?</div><div><br class=""></div><div>-glyph</div><br class=""></body></html>