On Tue, 2005-04-19 at 15:24, Guido van Rossum wrote:

> *If* we're going to create syntax for anonymous blocks, I think the
> primary use case ought to be cleanup operations to replace try/finally
> blocks for locking and similar things. I'd love to have syntactical
> support so I can write
> 
> blahblah(myLock):
>     code
>     code
>     code
> 
> instead of
> 
> myLock.acquire()
> try:
>     code
>     code
>     code
> finally:
>     myLock.release()

Indeed, it would be very cool to have these kind of (dare I say) block
decorators for managing resources.  The really nice thing about that is
when I have to protect multiple resources in a safe, but clean way
inside a single block.  Too many nested try/finally's cause you to
either get sloppy, or really ugly (or both!).

RSMotD (random stupid musing of the day): so I wonder if the decorator
syntax couldn't be extended for this kind of thing.

@acquire(myLock):
    code
    code
    code

-Barry

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to