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/2006-April/064309.html below:

[Python-Dev] Proposed addition to threading module

[Python-Dev] Proposed addition to threading module - released [Python-Dev] Proposed addition to threading module - released"Martin v. Löwis" martin at v.loewis.de
Tue Apr 25 01:35:46 CEST 2006
Tim Peters wrote:
> Does
> 
>     with cv:
> 
> work to replace the outer (== only) acquire/try/finally/release dance?

Indeed it does - although implemented in a somewhat convoluted way:
A lock *is* a context (or is that "context manager"), i.e. it implements

  def __context__(self): return self
  __enter__=acquire
  def __exit__(self,*args): return self.release() #roughly

A _Condition *has* a lock, so it could become the context (manager?)
through

  def __context__(self): return self.lock

However, instead of doing that, it does

  def __context__(self): return self
  # roughly: __enter__ is actually set in __init__ to self.lock.acquire
  def __enter__(self):
      return self.acquire()
  def __exit__(self):
      return self.release

Looks somewhat redundant to me, but correct.

Regards,
Martin
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