[Python-ideas] PEP 3156 / Tulip: stopping the loop while in run_until_complete
Saúl Ibarra Corretgé
saghul at gmail.com
Mon Feb 11 21:53:45 CET 2013
>
> The same thing as when no timeout is specified. I presume this means
> returning None. The alternative would be to call future.result() in all
> cases -- it would raise InvalidStateError, but that doesn't feel very
> useful. Perhaps this is actually the correct response? What is the
> reason you have something else that calls stop()?
>
I didn't run into this in practice, I just thought of it :-) I guess
that some exception handler or some third party lib could do it without
you knowing, but I don't have a good example on why someone would want
to do it.
>
> Yeah, that would not work, in my example the task is already started,
> I don't think cancel() will work midway.
>
> Actually, it may. There is code to throw CancelledError into the
> generator, in _step(). But I don't think it will necessarily break out
> of all blocking I/O. (Though it really should -- perhaps this is
> something useful to add tests for.)
>
Well, it may work for tasks, but since run_until_complete applies to
futures in general I'm not sure if that would still work.
I added the following review which fixes the problem and adds a test
case for it: https://codereview.appspot.com/7301076/ A few days ago I
also submitted this one: https://codereview.appspot.com/7312046/ which
adds a few more tests for run_until_complete.
Regards,
--
Saúl Ibarra Corretgé
http://saghul.net/blog | http://about.me/saghul
More information about the Python-ideas
mailing list