<div dir="ltr"><div>I read over the wait_one() proposal again, and I still don't understand it, so it would need more explanation to me.<br><br>But I don't see the point of avoiding callbacks. In this case, we have two or more in-flight requests that can be finished at any time. This does not have a synchronous code equivalent -- callbacks are pretty much the only mechanism we can use to be notified when something is done.<br>
<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Dec 19, 2012 at 12:26 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Tue, Dec 18, 2012 at 10:41 PM, Jasper St. Pierre<br>
<<a href="mailto:jstpierre@mecheye.net">jstpierre@mecheye.net</a>> wrote:<br>
> On Wed, Dec 19, 2012 at 1:24 AM, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
><br>
> ... snip ...<br>
><br>
>> That looks reasonable too, although the signature may need to be adjusted.<br>
>> (How does it cancel the remaining tasks if it wants to? Or does par() do<br>
>> that if this callback raises?) maybe call it filter?<br>
><br>
><br>
> The subtask completion callback can call abort() on the overall par_task,<br>
<br>
</div>Tasks don't have abort(), I suppose you meant cancel().<br>
<div class="im"><br>
> which could cancel the rest of the unfinished tasks.<br>
><br>
>     def abort_task(par_task, subtask):<br>
>         try:<br>
>             return subtask.result()<br>
>         except ValueError:<br>
>             par_task.abort()<br>
><br>
> The issue with this approach is that since the par() would return values<br>
> again, not tasks, we'd can't handle errors locally. Futures are also<br>
> immutable, so we can't modify the values after they resolve. Maybe we'd have<br>
> something like:<br>
><br>
>     def fail_silently(par_task, subtask):<br>
>         try:<br>
>             subtask.result()<br>
>         except ValueError as e:<br>
>             return Future.completed(None) # an already completed future that<br>
> has a value of None, sorry, don't remember the exact spelling<br>
>         else:<br>
>             return subtask<br>
><br>
> which allows us:<br>
><br>
>     for task in par(*tasks, subtask_completion=fail_silently):<br>
>         # ...<br>
><br>
> Which allows us both local error handling, as well as batch error handling.<br>
> But it's very verbose from the side of the callback. Hm.<br>
<br>
</div>Hm indeed. Unless you can get your thoughts straight I think I'd<br>
rather go with the wait_one() API, which can be used to build anything<br>
else you like, but doesn't require one to be quite so clever with<br>
callbacks. (Did I say I hate callbacks?)<br>
<div class="HOEnZb"><div class="h5"><br>
--<br>
--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>  Jasper<br>
</div>