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/2013-November/130557.html below:

[Python-Dev] [Python-checkins] cpython: asyncio: Change bounded semaphore into a subclass, like

[Python-Dev] [Python-checkins] cpython: asyncio: Change bounded semaphore into a subclass, like [Python-Dev] [Python-checkins] cpython: asyncio: Change bounded semaphore into a subclass, likeTim Peters tim.peters at gmail.com
Sun Nov 24 00:18:37 CET 2013
[guido]
> http://hg.python.org/cpython/rev/6bee0fdcba39
> changeset:   87468:6bee0fdcba39
> user:        Guido van Rossum <guido at python.org>
> date:        Sat Nov 23 15:09:16 2013 -0800
> summary:
>   asyncio: Change bounded semaphore into a subclass, like threading.[Bounded]Semaphore.
>
> files:
>   Lib/asyncio/locks.py                |  36 ++++++++--------
>   Lib/test/test_asyncio/test_locks.py |   2 +-
>   2 files changed, 20 insertions(+), 18 deletions(-)
>
>
> diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py
> --- a/Lib/asyncio/locks.py
> +++ b/Lib/asyncio/locks.py
> @@ -336,22 +336,15 @@

...
> +class BoundedSemaphore(Semaphore):
...
> +    def release(self):
> +        if self._value >= self._bound_value:
> +            raise ValueError('BoundedSemaphore released too many times')
> +        super().release()

If there's a lock and parallelism involved, this release()
implementation is vulnerable to races:  any number of threads can see
"self._value < self._bound_value" before one of them manages to call
the superclass release(), and so self._value can become arbitrarily
larger than self._bound_value.  I fixed the same bug in threading's
similar bounded semaphore class a few weeks ago.
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