aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/concurrent/futures/_base.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Lib/concurrent/futures/_base.py
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/concurrent/futures/_base.py')
-rw-r--r--contrib/tools/python3/src/Lib/concurrent/futures/_base.py100
1 files changed, 50 insertions, 50 deletions
diff --git a/contrib/tools/python3/src/Lib/concurrent/futures/_base.py b/contrib/tools/python3/src/Lib/concurrent/futures/_base.py
index 78d17dca4d..5c00f2edbe 100644
--- a/contrib/tools/python3/src/Lib/concurrent/futures/_base.py
+++ b/contrib/tools/python3/src/Lib/concurrent/futures/_base.py
@@ -7,7 +7,7 @@ import collections
import logging
import threading
import time
-import types
+import types
FIRST_COMPLETED = 'FIRST_COMPLETED'
FIRST_EXCEPTION = 'FIRST_EXCEPTION'
@@ -54,10 +54,10 @@ class TimeoutError(Error):
"""The operation exceeded the given deadline."""
pass
-class InvalidStateError(Error):
- """The operation is not allowed in this state."""
- pass
-
+class InvalidStateError(Error):
+ """The operation is not allowed in this state."""
+ pass
+
class _Waiter(object):
"""Provides the event that wait() and as_completed() block on."""
def __init__(self):
@@ -284,14 +284,14 @@ def wait(fs, timeout=None, return_when=ALL_COMPLETED):
A named 2-tuple of sets. The first set, named 'done', contains the
futures that completed (is finished or cancelled) before the wait
completed. The second set, named 'not_done', contains uncompleted
- futures. Duplicate futures given to *fs* are removed and will be
- returned only once.
+ futures. Duplicate futures given to *fs* are removed and will be
+ returned only once.
"""
- fs = set(fs)
+ fs = set(fs)
with _AcquireFutures(fs):
- done = {f for f in fs
- if f._state in [CANCELLED_AND_NOTIFIED, FINISHED]}
- not_done = fs - done
+ done = {f for f in fs
+ if f._state in [CANCELLED_AND_NOTIFIED, FINISHED]}
+ not_done = fs - done
if (return_when == FIRST_COMPLETED) and done:
return DoneAndNotDoneFutures(done, not_done)
elif (return_when == FIRST_EXCEPTION) and done:
@@ -310,7 +310,7 @@ def wait(fs, timeout=None, return_when=ALL_COMPLETED):
f._waiters.remove(waiter)
done.update(waiter.finished_futures)
- return DoneAndNotDoneFutures(done, fs - done)
+ return DoneAndNotDoneFutures(done, fs - done)
class Future(object):
"""Represents the result of an asynchronous computation."""
@@ -387,11 +387,11 @@ class Future(object):
def __get_result(self):
if self._exception:
- try:
- raise self._exception
- finally:
- # Break a reference cycle with the exception in self._exception
- self = None
+ try:
+ raise self._exception
+ finally:
+ # Break a reference cycle with the exception in self._exception
+ self = None
else:
return self._result
@@ -410,10 +410,10 @@ class Future(object):
if self._state not in [CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED]:
self._done_callbacks.append(fn)
return
- try:
- fn(self)
- except Exception:
- LOGGER.exception('exception calling callback for %r', self)
+ try:
+ fn(self)
+ except Exception:
+ LOGGER.exception('exception calling callback for %r', self)
def result(self, timeout=None):
"""Return the result of the call that the future represents.
@@ -431,24 +431,24 @@ class Future(object):
timeout.
Exception: If the call raised then that exception will be raised.
"""
- try:
- with self._condition:
- if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
- raise CancelledError()
- elif self._state == FINISHED:
- return self.__get_result()
-
- self._condition.wait(timeout)
-
- if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
- raise CancelledError()
- elif self._state == FINISHED:
- return self.__get_result()
- else:
- raise TimeoutError()
- finally:
- # Break a reference cycle with the exception in self._exception
- self = None
+ try:
+ with self._condition:
+ if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
+ raise CancelledError()
+ elif self._state == FINISHED:
+ return self.__get_result()
+
+ self._condition.wait(timeout)
+
+ if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
+ raise CancelledError()
+ elif self._state == FINISHED:
+ return self.__get_result()
+ else:
+ raise TimeoutError()
+ finally:
+ # Break a reference cycle with the exception in self._exception
+ self = None
def exception(self, timeout=None):
"""Return the exception raised by the call that the future represents.
@@ -530,8 +530,8 @@ class Future(object):
Should only be used by Executor implementations and unit tests.
"""
with self._condition:
- if self._state in {CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED}:
- raise InvalidStateError('{}: {!r}'.format(self._state, self))
+ if self._state in {CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED}:
+ raise InvalidStateError('{}: {!r}'.format(self._state, self))
self._result = result
self._state = FINISHED
for waiter in self._waiters:
@@ -545,8 +545,8 @@ class Future(object):
Should only be used by Executor implementations and unit tests.
"""
with self._condition:
- if self._state in {CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED}:
- raise InvalidStateError('{}: {!r}'.format(self._state, self))
+ if self._state in {CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED}:
+ raise InvalidStateError('{}: {!r}'.format(self._state, self))
self._exception = exception
self._state = FINISHED
for waiter in self._waiters:
@@ -554,12 +554,12 @@ class Future(object):
self._condition.notify_all()
self._invoke_callbacks()
- __class_getitem__ = classmethod(types.GenericAlias)
-
+ __class_getitem__ = classmethod(types.GenericAlias)
+
class Executor(object):
"""This is an abstract base class for concrete asynchronous executors."""
- def submit(self, fn, /, *args, **kwargs):
+ def submit(self, fn, /, *args, **kwargs):
"""Submits a callable to be executed with the given arguments.
Schedules the callable to be executed as fn(*args, **kwargs) and returns
@@ -614,7 +614,7 @@ class Executor(object):
future.cancel()
return result_iterator()
- def shutdown(self, wait=True, *, cancel_futures=False):
+ def shutdown(self, wait=True, *, cancel_futures=False):
"""Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other
@@ -624,9 +624,9 @@ class Executor(object):
wait: If True then shutdown will not return until all running
futures have finished executing and the resources used by the
executor have been reclaimed.
- cancel_futures: If True then shutdown will cancel all pending
- futures. Futures that are completed or running will not be
- cancelled.
+ cancel_futures: If True then shutdown will cancel all pending
+ futures. Futures that are completed or running will not be
+ cancelled.
"""
pass