[Python-ideas] [Python-Dev] PEP 3156 - Asynchronous IO Support Rebooted

Richard Oudkerk shibturn at gmail.com
Wed Jan 9 13:13:19 CET 2013


On 09/01/2013 10:54am, Nick Coghlan wrote:
> You need to combine it with the other LBYL checks (f.done() and
> f.cancelled()) to be sure it won't throw an exception.
>
>      if f.done() and not f.cancelled():
>          # Since we now know neither TimeoutError nor CancelledError can happen,
>          # we can check for exceptions either by calling f.exception() or
>          # by calling f.result() inside a try/except block
>          # The latter will usually be the better option
>
> Just calling f.result() is by far the most common, but the other can
> be convenient in some cases (e.g. if you're writing a scheduler that
> needs to check if it should be calling send() or throw() on a
> generator).

Which goes to show that it cannot be used with LBYL.

For exception() to be usable with LBYL one would need to be able to 
check that exception() returns a value without having to catch any 
exceptions -- either from exception() or from result().

But you can only check that exception() doesn't raise an error by 
calling result() to ensure that it does raise an error.  But then you 
might as well catch the exception from result().

And the idea of calling exception() first and then result() if it fails 
is just crazy.

As things stand, exception() is pointless.

-- 
Richard




More information about the Python-ideas mailing list