<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">So, just going point by point:<div><br></div><div>Yes, absolutely put this off for 3.8. I didn’t know the freeze was so close or I would have put the 3.8 tag on originally.</div><div><br></div><div>Yes, absolutely it is only meant for concurrent.futures futures, it only changes async where async uses concurrent.futures futures.</div><div><br></div><div>Here’s a more fleshed out description of the use case:</div><div><br></div><div>Assume you have two functions. Function a(x: str)->AResult fetches an AResult object from a web resource, function b(y: AResult) performs some computationally heavy work on AResult.</div><div><br></div><div>Assume you’re calling a 10 times with a threadpoolexecutor with 2 worker theads.  If you were to schedule a as future using submit, and b as a callback, the executions would look like this:</div><div><br></div><div>ExecutorThread: b*10</div><div>Worker1: a*5</div><div>Worker2: a*5</div><div><br></div><div>This only gets worse as more work (b) is scheduled as a callback for the result from a.</div><div><br></div><div>Now you could resolve this by, instead of submitting b as a callback, submitting the following lambda:</div><div><br></div><div>lambda x: executor.submit(b, x) </div><div><br></div><div>But then you wouldn’t have easy access to this new future. You would have to build a lot of boilerplate code to collect that future into some external collection, and this would only get worse the deeper the nesting goes.</div><div><br></div><div>With this syntax on the other hand, if you run a 10 times using submit, but then run a_fut.then(b) for each future, execution instead looks like this:</div><div><br></div><div><div><span style="background-color: rgba(255, 255, 255, 0);">ExecutorThread: </span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Worker1: a*5 b*5</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Worker2: a*5 b*5</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">You can also do additional depth easily. Suppose you want to run 3 c operations (processes the output of b) for each b operation. Then you could call this like</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">b_fut = a_fut.then(b)</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div>for i in range(3):</div><div>    b_fut.then(c)</div><div><br></div><div>And the execution would look like this:</div><div><br></div><div><div><span style="background-color: rgba(255, 255, 255, 0);">ExecutorThread:</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Worker1: a*5 b*5 c*15</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Worker2: a*5 b*5 c*15</span></div></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Which would be very difficult to do otherwise, and distributes the load across the workers, while having direct access to the outputs of the calls to c.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">-dancollins34</span></div><br><div id="AppleMailSignature">Sent from my iPhone</div><div><br>On Jan 26, 2018, at 1:07 AM, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div>I really don't want to distract Yury with this. Let's consider this (or something that addresses the same need) for 3.8.<br><br>To be clear this is meant as a feature for concurrent.futures.Future, not for asyncio.Future. (It's a bit confusing since you also change asyncio.)<br><br>Also to be honest I don't understand the use case *or* the semantics very well. You have some explaining to do...<br><br></div>(Also, full links: <a href="https://bugs.python.org/issue32672">https://bugs.python.org/issue32672</a>; <a href="https://github.com/python/cpython/pull/5335">https://github.com/python/cpython/pull/5335</a>)<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 25, 2018 at 8:38 PM, Daniel Collins <span dir="ltr"><<a href="mailto:dancollins34@gmail.com" target="_blank">dancollins34@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Hello all,<div><br></div><div>So, first time posting here. I’ve been bothered for a while about the lack of the ability to chain futures in python, such that the next future will execute upon the first’s completion.  So I submitted a pr to do this.  This would add the .then(self, fn) method to concurrent.futures.Future.  Thoughts?</div><div><br></div><div>-dancollins34</div><div><br></div><div>Github PR #5335</div><div><a href="http://bugs.python.org" target="_blank">bugs.python.org</a> issue #32672</div></div><br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>
</div></blockquote></div></body></html>