diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-25 10:46:04 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-25 10:46:04 +0300 |
commit | 4a07b03673d315e0d98c5e29cc9cbeeec1d5c94f (patch) | |
tree | 7cdc507d170dc6f879b1fde1093012f5be58fece /contrib/tools/python3/src/Lib/asyncio/locks.py | |
parent | 86f93d737e9db0e8bfdb6d6a291b6dbdab9d1bdb (diff) | |
download | ydb-4a07b03673d315e0d98c5e29cc9cbeeec1d5c94f.tar.gz |
intermediate changes
ref:ac52b2b4969cd1562fcebef15e16af428f77648b
Diffstat (limited to 'contrib/tools/python3/src/Lib/asyncio/locks.py')
-rw-r--r-- | contrib/tools/python3/src/Lib/asyncio/locks.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/contrib/tools/python3/src/Lib/asyncio/locks.py b/contrib/tools/python3/src/Lib/asyncio/locks.py index f1ce7324785..d17d7ccd813 100644 --- a/contrib/tools/python3/src/Lib/asyncio/locks.py +++ b/contrib/tools/python3/src/Lib/asyncio/locks.py @@ -378,6 +378,7 @@ class Semaphore(_ContextManagerMixin): warnings.warn("The loop argument is deprecated since Python 3.8, " "and scheduled for removal in Python 3.10.", DeprecationWarning, stacklevel=2) + self._wakeup_scheduled = False def __repr__(self): res = super().__repr__() @@ -391,6 +392,7 @@ class Semaphore(_ContextManagerMixin): waiter = self._waiters.popleft() if not waiter.done(): waiter.set_result(None) + self._wakeup_scheduled = True return def locked(self): @@ -406,16 +408,17 @@ class Semaphore(_ContextManagerMixin): called release() to make it larger than 0, and then return True. """ - while self._value <= 0: + # _wakeup_scheduled is set if *another* task is scheduled to wakeup + # but its acquire() is not resumed yet + while self._wakeup_scheduled or self._value <= 0: fut = self._loop.create_future() self._waiters.append(fut) try: await fut - except: - # See the similar code in Queue.get. - fut.cancel() - if self._value > 0 and not fut.cancelled(): - self._wake_up_next() + # reset _wakeup_scheduled *after* waiting for a future + self._wakeup_scheduled = False + except exceptions.CancelledError: + self._wake_up_next() raise self._value -= 1 return True |