[Python-Dev] pep 310 (reliable acquisition/release pairs)

Holger Krekel hpk at trillke.net
Fri Sep 19 11:42:40 EDT 2003


hello, 

admittedly i only followed Brett's very nice summaries (thanks!) 
in the last month so i may have missed some details. But here are a few
comments regarding "PEP 310 Reliable Acquisition/Release Pairs". 

The PEP actually is about interacting with the execution 
of a code block.  It allows to define (one-shot) interception points 
for entering and leaving a code block.  Now there are at least 
two interesting cases which the PEP does (quite explicitely) not cover:

- what to do with exceptions 

- what to do with yield 

IMHO introducing a new block statement at this stage in language 
development warrants an effort to tackle these cases (and maybe more
like e.g. allowing the handler to trigger looping). 

This is probably best done with trying to directly design a protocol between
the "interpreter-loop" and the - what i'd call - the "execution handler". 

And here it seems much more important to provide a concise definition 
of such a protocol (enter/leave/except/whatever) than to try to find 
an exact equivalence to plain python code.  "Execution events" are really 
occuring at several points/bytecodes in the eval-loop and a plain python 
construct can only go so far. 

for example, you *could* say something like 

    __enter__   called every time execution of the code block resumes
                (including when it is entered the first time)

but this is not easily expressed in plain Python code although it seems
implementable (and useful for resource-control when yielding).

So while i am not strictly against the proposal i'd humbly ask for not
hurrying into accepting the PEP as is. Python 2.4 is not closeby  so 
i hope there is still some time to discuss this. I have done some 
practical experiments ("x-python") which actually incorporate XML-syntax 
into Python using a concept of an execution handler (tags are execution
handlers and can additionally "catch" unassigned/dropped values that would
otherwise be POP_TOPed). While this is impossible to ever appear in 
official Python i'd like to think about and report some experiences - 
but not before Novemeber because the next PyPy sprint and other stuff 
is keeping me far too busy.  

thanks & regards,

    holger



More information about the Python-Dev mailing list