A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-April/052862.html below:

[Python-Dev] anonymous blocks

[Python-Dev] anonymous blocks [Python-Dev] anonymous blocksTimothy Fitz firemoth at gmail.com
Sat Apr 23 05:42:49 CEST 2005
On 4/21/05, Guido van Rossum <gvanrossum at gmail.com> wrote: 
>    for dummy in synchronized(the_lock):
>        BODY
> 
> or perhaps even (making "for VAR" optional in the for-loop syntax)
> with
> 
>    in synchronized(the_lock):
>        BODY
> 
> Then synchronized() could be written cleanly as follows:
> 
>    def synchronized(lock):
>        lock.acquire()
>        try:
>            yield None
>        finally:
>            lock.release()

How is this different from:

def synchronized(lock):
  def synch_fn(block):
    lock.acquire()
    try:
      block()
    finally:
      lock.release()
  return synch_fn

@synchronized
def foo():
  BLOCK

True, it's non-obvious that foo is being immediately executed, but
regardless I like the way synchronized is defined, and doesn't use
yield (which in my opinion is a non-obvious solution)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4