[Python-Dev] PEP 343 - next steps

Nick Coghlan ncoghlan at gmail.com
Mon Jun 13 03:58:18 CEST 2005


Guido van Rossum wrote:
> I can't make time for this right now, but the more I think about it,
> the more I believe the worry about asynchronous exceptions is mostly
> irrational. Despite your "proof" that it *can* be implemented I really
> don't want to see anything like that implemented -- I doubt that
> you've covered all the cases and I don't like inserting new opcodes to
> handle a case that most programs don't care about. Declaring something
> "atomic" that could span an arbitrary amount of Python code execution
> (including calls) just doesn't seem right.

As I just added to the Wiki, dropping the issue completely works for 
me. I'm also far from convinced I'd covered all the corner cases 
(besides, blocking KeyboardInterrupt for an arbitrary amount of time 
made me uncomfortable).

> Disregarding asynchronous exceptions, you can already use
> with-statements for your beloved RAII pattern, right? I'm still
> skeptical how important it is in Python -- its seems something
> invented very specifically for C++'s guarantee of local destructor
> execution, and I don't expect to see all that many applications for it
> in Python.

You'd mostly convinced me that RAII was rare in Python, but two 
possible use cases remained - files, and "call method X of object Y at 
the end of the block" (e.g. "closing()" from the PEP).

Both of those would require any async guarantee to cover evaluation of 
EXPR in order to be included in the guarantee. If with statements make 
no guarantees about async exceptions, then there is no problem (as 
there is officially no difference between the two styles).

If we ever do resurrect the idea, I also realised a far simpler 
solution would involve moving evaluation of EXPR and the call to 
__enter__ inside the try/finally block, and having an internal flag to 
indicate whether or not __exit__ should be called as the block is 
exited. Far less screwing around with ceval.c, and far easier to get 
right.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.blogspot.com


More information about the Python-Dev mailing list