<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Feb 11, 2013 at 2:23 PM, Saúl Ibarra Corretgé <span dir="ltr"><<a href="mailto:saghul@gmail.com" target="_blank">saghul@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im"><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I think there are actually two cases: where stop() is called from the<br>
task given to run_until_complete(), or from another task. In the former<br>
case, because the exception bubbles out of the task's coroutine, the<br>
task will be marked as done (and its exception set to _StopError) -- at<br>
least I think so. In the latter case, the task will still be runnable,<br>
and it will continue to run when the event loop is started again. (Hm...<br>
maybe run_forever() should be called start(), to match stop()?)<br>
<br>
I think your unittest only tests the former case.<br>
<br>
</blockquote>
<br></div>
Well, I think they are actually the same. In the gist I posted earlier I called loop.stop(), I didn't raise the exception inside the task, and loop.stop() will call call_soon so the actual raising will happen in the context on _run_once unless I'm mistaken.<br>

</blockquote><div><br></div><div>Oh, you're right! Not my day for reading carefully. :-)<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">


Here is an updated simple test with it's output: <a href="https://gist.github.com/saghul/4758151" target="_blank">https://gist.github.com/saghul/4758151</a><div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I'm not sure what run_until_complete() should return in the latter case.<br>
In fact it makes me doubt the behavior of run_until_complete() in<br>
general. Maybe it should return the Future (although that's kind of<br>
redundant)? Or an enum indicating what happened? (Cases would be result,<br>
exception, timeout, running -- and maybe cancelled?)<br>
<br>
</blockquote>
<br></div>
I think the current behavior is ok, it the user really wants to check if the future was actually completed she can check with done(), if she saved the future in a variable, that is.<br>
<br>
My other preferred approach would be to raise an exception, since I consider this an exceptional case: I told the loop to run until this future is completed so I expect that to happen. Since it didn't, NotCompletedError (or something alike) sounds good to me.<br>

</blockquote></div><br></div><div class="gmail_extra">Good. How about calling future.result(), and letting it raise InvalidStateError ? (Except if the timeout handler was called.)<br clear="all"></div><div class="gmail_extra">

<br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div></div>