<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 8, 2016 at 1:52 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">Glyph, Ben, Amber,<br>
<br>
So what’s the resolution on Future.__isfuture__ and fixing the<br>
isinstance(obj, Future) checks from asyncio?<br>
<br>
3.5.2 RC is only few days away, I can still make the change if<br>
it’s a blocker for Twisted and Tornado.<br></blockquote><div><br></div><div>None of this is blocking Tornado - we shipped asyncio integration six months ago. There's some room for improvement, but I don't think there's a clear enough mandate to squeeze something in for this release. I'd rather take the time to sort out a more complete plan before the next release. </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">
<span class="HOEnZb"><font color="#888888"><br>
Yury<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> On Jun 6, 2016, at 5:35 PM, Glyph <<a href="mailto:glyph@twistedmatrix.com">glyph@twistedmatrix.com</a>> wrote:<br>
><br>
>><br>
>> On Jun 6, 2016, at 14:21, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
>><br>
>> On Mon, Jun 6, 2016 at 1:54 PM, Glyph <<a href="mailto:glyph@twistedmatrix.com">glyph@twistedmatrix.com</a>> wrote:<br>
>><br>
>><br>
>>> On Jun 6, 2016, at 08:29, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
>>><br>
>>> On Sun, Jun 5, 2016 at 10:16 PM, Glyph <<a href="mailto:glyph@twistedmatrix.com">glyph@twistedmatrix.com</a>> wrote:<br>
>>>><br>
>>>> On Jun 4, 2016, at 13:25, Ben Darnell <<a href="mailto:ben@bendarnell.com">ben@bendarnell.com</a>> wrote:<br>
>>>><br>
>>>> If things are so sensitive to minor changes in timing, doesn't that set the<br>
>>>> bar impossibly high for interoperability?<br>
>>>><br>
>>>><br>
>>>> The sensitivity is not to changes in timing - i.e. when the wall-clock runs,<br>
>>>> or ordering of non-deterministically ordered events - but rather to<br>
>>>> reentrancy - whether certain things complete synchronously while the caller<br>
>>>> is still on the stack and can depend on them having done so upon return.<br>
>>>><br>
>>>> The recommended way of writing tests within Twisted these days depends<br>
>>>> heavily on `.callback´ synchronously resolving a Deferred, which is what<br>
>>>> adding a call_soon breaks.<br>
>>><br>
>>> That's interesting, and also potentially worrisome (for interop, I'm<br>
>>> not saying Twisted is wrong here).<br>
>>><br>
>>> I think asyncio depends on the opposite: that if you add a callback to<br>
>>> a Future that's ready it does *not* immediately run. Asyncio's promise<br>
>>> is pretty strongly that callbacks are serialized (no callbacks running<br>
>>> inside other callbacks). IIRC we experimented with other semantics and<br>
>>> found that it was harder to reason about. (IMO if you *know* a Future<br>
>>> is ready why add a callback to it rather than just calling the damn<br>
>>> thing if that's what you want?)<br>
>><br>
>> I don't think Twisted is necessarily right 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:<br>
>><br>
>> def test(test_case):<br>
>>     a = asynchronously_something()<br>
>>     test_case.this_must_not_have_a_result(a)<br>
>>     cause_a_to_fire()<br>
>>     test_case.assertEqual(test_case.this_must_have_a_result(a), something)<br>
>><br>
>> 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?<br>
>><br>
>> Right. I'm still unclear on what the compelling use case for that is (other than that Twisted has always done this). Is it performance? Is it callback ordering?<br>
><br>
> Very, very early in the development of Deferreds, they worked the way Futures do; we changed it mainly to reduce coupling to the event loop so that we could test general-purpose algorithms (like gatherResults) without needing to spin an event loop to do it.  So the main use-case is testing.<br>
><br>
>> I suppose Deferred has a method to mark it done.<br>
><br>
> Yep; ".callback".<br>
><br>
>> Does that immediately run the callbacks?<br>
><br>
> It runs callbacks up to the point that the first one returns a Deferred, and then it waits for that one to be fired to continue running the chain.<br>
><br>
> There is an exception here, where Deferred effectively opts in to Future-like behavior in a very specific case: if you are recursively giving results to a Deferred X that would un-block a Deferred Y inside a callback on Y, Y will not execute its own callbacks reentrantly; it waits until the current callback is done.<br>
><br>
> So while the semantics of .callback() on a Deferred are clear-cut with respect to that Deferred itself, "continue any Deferreds waiting upon it" is a callback-like structure that is slightly squirrely in a very call_soon-like way to avoid surprise reentrancy and RecursionError explosions when having a structure like an asynchronous 'for' loop.<br>
><br>
>> Or does it come in two flavors? Can a Deferred that's marked done ever revert back to being not done?<br>
><br>
> No.  A Deferred that has been called back stays called back; callbacking it again is always an error.  However, it may pause running its chain if you return another Deferred in the middle someplace; the way to resume it is to give the inner Deferred a result; the outer one cannot be otherwise compelled to continue.<br>
><br>
>> (I believe I once read the Deferred code enough to be able to find the answers, but I'm afraid I've never really needed what I learned then, so I've forgotten...)<br>
><br>
> Happy to fill in these blanks; they're (mostly, modulo the weird exception for callbacks-in-callbacks) straightforward :).<br>
><br>
> -glyph<br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<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><br>
<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>