summaryrefslogtreecommitdiffstats
path: root/contrib/python/grpcio/py3/grpc/framework/foundation
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-08-29 14:19:24 +0300
committerrobot-piglet <[email protected]>2025-08-29 14:40:38 +0300
commit5715939b5b1a1812ed85171fb519f9c1c3c326e8 (patch)
tree5d981253427e490749bbb50d3616507fa0d6d1bc /contrib/python/grpcio/py3/grpc/framework/foundation
parentc390a008ee5d15e1d8f49326671908f375e0851b (diff)
Intermediate changes
commit_hash:88dd3a7e237f5ebeb9b302a0e6866042635fda83
Diffstat (limited to 'contrib/python/grpcio/py3/grpc/framework/foundation')
-rw-r--r--contrib/python/grpcio/py3/grpc/framework/foundation/abandonment.py6
-rw-r--r--contrib/python/grpcio/py3/grpc/framework/foundation/callable_util.py64
-rw-r--r--contrib/python/grpcio/py3/grpc/framework/foundation/future.py164
-rw-r--r--contrib/python/grpcio/py3/grpc/framework/foundation/logging_pool.py23
-rw-r--r--contrib/python/grpcio/py3/grpc/framework/foundation/stream.py12
5 files changed, 137 insertions, 132 deletions
diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/abandonment.py b/contrib/python/grpcio/py3/grpc/framework/foundation/abandonment.py
index 660ce991c41..c4cb7d5c072 100644
--- a/contrib/python/grpcio/py3/grpc/framework/foundation/abandonment.py
+++ b/contrib/python/grpcio/py3/grpc/framework/foundation/abandonment.py
@@ -17,6 +17,6 @@
class Abandoned(Exception):
"""Indicates that some computation is being abandoned.
- Abandoning a computation is different than returning a value or raising
- an exception indicating some operational or programming defect.
- """
+ Abandoning a computation is different than returning a value or raising
+ an exception indicating some operational or programming defect.
+ """
diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/callable_util.py b/contrib/python/grpcio/py3/grpc/framework/foundation/callable_util.py
index 0a638eb62e8..b64131b4029 100644
--- a/contrib/python/grpcio/py3/grpc/framework/foundation/callable_util.py
+++ b/contrib/python/grpcio/py3/grpc/framework/foundation/callable_util.py
@@ -25,14 +25,14 @@ _LOGGER = logging.getLogger(__name__)
class Outcome(ABC):
"""A sum type describing the outcome of some call.
- Attributes:
- kind: One of Kind.RETURNED or Kind.RAISED respectively indicating that the
- call returned a value or raised an exception.
- return_value: The value returned by the call. Must be present if kind is
- Kind.RETURNED.
- exception: The exception raised by the call. Must be present if kind is
- Kind.RAISED.
- """
+ Attributes:
+ kind: One of Kind.RETURNED or Kind.RAISED respectively indicating that the
+ call returned a value or raised an exception.
+ return_value: The value returned by the call. Must be present if kind is
+ Kind.RETURNED.
+ exception: The exception raised by the call. Must be present if kind is
+ Kind.RAISED.
+ """
@enum.unique
class Kind(enum.Enum):
@@ -43,15 +43,19 @@ class Outcome(ABC):
class _EasyOutcome(
- collections.namedtuple('_EasyOutcome',
- ['kind', 'return_value', 'exception']), Outcome):
+ collections.namedtuple(
+ "_EasyOutcome", ["kind", "return_value", "exception"]
+ ),
+ Outcome,
+):
"""A trivial implementation of Outcome."""
def _call_logging_exceptions(behavior, message, *args, **kwargs):
try:
- return _EasyOutcome(Outcome.Kind.RETURNED, behavior(*args, **kwargs),
- None)
+ return _EasyOutcome(
+ Outcome.Kind.RETURNED, behavior(*args, **kwargs), None
+ )
except Exception as e: # pylint: disable=broad-except
_LOGGER.exception(message)
return _EasyOutcome(Outcome.Kind.RAISED, None, e)
@@ -60,16 +64,16 @@ def _call_logging_exceptions(behavior, message, *args, **kwargs):
def with_exceptions_logged(behavior, message):
"""Wraps a callable in a try-except that logs any exceptions it raises.
- Args:
- behavior: Any callable.
- message: A string to log if the behavior raises an exception.
+ Args:
+ behavior: Any callable.
+ message: A string to log if the behavior raises an exception.
- Returns:
- A callable that when executed invokes the given behavior. The returned
- callable takes the same arguments as the given behavior but returns a
- future.Outcome describing whether the given behavior returned a value or
- raised an exception.
- """
+ Returns:
+ A callable that when executed invokes the given behavior. The returned
+ callable takes the same arguments as the given behavior but returns a
+ future.Outcome describing whether the given behavior returned a value or
+ raised an exception.
+ """
@functools.wraps(behavior)
def wrapped_behavior(*args, **kwargs):
@@ -81,14 +85,14 @@ def with_exceptions_logged(behavior, message):
def call_logging_exceptions(behavior, message, *args, **kwargs):
"""Calls a behavior in a try-except that logs any exceptions it raises.
- Args:
- behavior: Any callable.
- message: A string to log if the behavior raises an exception.
- *args: Positional arguments to pass to the given behavior.
- **kwargs: Keyword arguments to pass to the given behavior.
+ Args:
+ behavior: Any callable.
+ message: A string to log if the behavior raises an exception.
+ *args: Positional arguments to pass to the given behavior.
+ **kwargs: Keyword arguments to pass to the given behavior.
- Returns:
- An Outcome describing whether the given behavior returned a value or raised
- an exception.
- """
+ Returns:
+ An Outcome describing whether the given behavior returned a value or raised
+ an exception.
+ """
return _call_logging_exceptions(behavior, message, *args, **kwargs)
diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/future.py b/contrib/python/grpcio/py3/grpc/framework/foundation/future.py
index c7996aa8a56..73b0d0bdbe1 100644
--- a/contrib/python/grpcio/py3/grpc/framework/foundation/future.py
+++ b/contrib/python/grpcio/py3/grpc/framework/foundation/future.py
@@ -45,9 +45,9 @@ class CancelledError(Exception):
class Future(abc.ABC):
"""A representation of a computation in another control flow.
- Computations represented by a Future may be yet to be begun, may be ongoing,
- or may have already completed.
- """
+ Computations represented by a Future may be yet to be begun, may be ongoing,
+ or may have already completed.
+ """
# NOTE(nathaniel): This isn't the return type that I would want to have if it
# were up to me. Were this interface being written from scratch, the return
@@ -63,17 +63,17 @@ class Future(abc.ABC):
def cancel(self):
"""Attempts to cancel the computation.
- This method does not block.
-
- Returns:
- True if the computation has not yet begun, will not be allowed to take
- place, and determination of both was possible without blocking. False
- under all other circumstances including but not limited to the
- computation's already having begun, the computation's already having
- finished, and the computation's having been scheduled for execution on a
- remote system for which a determination of whether or not it commenced
- before being cancelled cannot be made without blocking.
- """
+ This method does not block.
+
+ Returns:
+ True if the computation has not yet begun, will not be allowed to take
+ place, and determination of both was possible without blocking. False
+ under all other circumstances including but not limited to the
+ computation's already having begun, the computation's already having
+ finished, and the computation's having been scheduled for execution on a
+ remote system for which a determination of whether or not it commenced
+ before being cancelled cannot be made without blocking.
+ """
raise NotImplementedError()
# NOTE(nathaniel): Here too this isn't the return type that I'd want this
@@ -94,27 +94,27 @@ class Future(abc.ABC):
def cancelled(self):
"""Describes whether the computation was cancelled.
- This method does not block.
+ This method does not block.
- Returns:
- True if the computation was cancelled any time before its result became
- immediately available. False under all other circumstances including but
- not limited to this object's cancel method not having been called and
- the computation's result having become immediately available.
- """
+ Returns:
+ True if the computation was cancelled any time before its result became
+ immediately available. False under all other circumstances including but
+ not limited to this object's cancel method not having been called and
+ the computation's result having become immediately available.
+ """
raise NotImplementedError()
@abc.abstractmethod
def running(self):
"""Describes whether the computation is taking place.
- This method does not block.
+ This method does not block.
- Returns:
- True if the computation is scheduled to take place in the future or is
- taking place now, or False if the computation took place in the past or
- was cancelled.
- """
+ Returns:
+ True if the computation is scheduled to take place in the future or is
+ taking place now, or False if the computation took place in the past or
+ was cancelled.
+ """
raise NotImplementedError()
# NOTE(nathaniel): These aren't quite the semantics I'd like here either. I
@@ -125,95 +125,95 @@ class Future(abc.ABC):
def done(self):
"""Describes whether the computation has taken place.
- This method does not block.
+ This method does not block.
- Returns:
- True if the computation is known to have either completed or have been
- unscheduled or interrupted. False if the computation may possibly be
- executing or scheduled to execute later.
- """
+ Returns:
+ True if the computation is known to have either completed or have been
+ unscheduled or interrupted. False if the computation may possibly be
+ executing or scheduled to execute later.
+ """
raise NotImplementedError()
@abc.abstractmethod
def result(self, timeout=None):
"""Accesses the outcome of the computation or raises its exception.
- This method may return immediately or may block.
+ This method may return immediately or may block.
- Args:
- timeout: The length of time in seconds to wait for the computation to
- finish or be cancelled, or None if this method should block until the
- computation has finished or is cancelled no matter how long that takes.
+ Args:
+ timeout: The length of time in seconds to wait for the computation to
+ finish or be cancelled, or None if this method should block until the
+ computation has finished or is cancelled no matter how long that takes.
- Returns:
- The return value of the computation.
+ Returns:
+ The return value of the computation.
- Raises:
- TimeoutError: If a timeout value is passed and the computation does not
- terminate within the allotted time.
- CancelledError: If the computation was cancelled.
- Exception: If the computation raised an exception, this call will raise
- the same exception.
- """
+ Raises:
+ TimeoutError: If a timeout value is passed and the computation does not
+ terminate within the allotted time.
+ CancelledError: If the computation was cancelled.
+ Exception: If the computation raised an exception, this call will raise
+ the same exception.
+ """
raise NotImplementedError()
@abc.abstractmethod
def exception(self, timeout=None):
"""Return the exception raised by the computation.
- This method may return immediately or may block.
+ This method may return immediately or may block.
- Args:
- timeout: The length of time in seconds to wait for the computation to
- terminate or be cancelled, or None if this method should block until
- the computation is terminated or is cancelled no matter how long that
- takes.
+ Args:
+ timeout: The length of time in seconds to wait for the computation to
+ terminate or be cancelled, or None if this method should block until
+ the computation is terminated or is cancelled no matter how long that
+ takes.
- Returns:
- The exception raised by the computation, or None if the computation did
- not raise an exception.
+ Returns:
+ The exception raised by the computation, or None if the computation did
+ not raise an exception.
- Raises:
- TimeoutError: If a timeout value is passed and the computation does not
- terminate within the allotted time.
- CancelledError: If the computation was cancelled.
- """
+ Raises:
+ TimeoutError: If a timeout value is passed and the computation does not
+ terminate within the allotted time.
+ CancelledError: If the computation was cancelled.
+ """
raise NotImplementedError()
@abc.abstractmethod
def traceback(self, timeout=None):
"""Access the traceback of the exception raised by the computation.
- This method may return immediately or may block.
+ This method may return immediately or may block.
- Args:
- timeout: The length of time in seconds to wait for the computation to
- terminate or be cancelled, or None if this method should block until
- the computation is terminated or is cancelled no matter how long that
- takes.
+ Args:
+ timeout: The length of time in seconds to wait for the computation to
+ terminate or be cancelled, or None if this method should block until
+ the computation is terminated or is cancelled no matter how long that
+ takes.
- Returns:
- The traceback of the exception raised by the computation, or None if the
- computation did not raise an exception.
+ Returns:
+ The traceback of the exception raised by the computation, or None if the
+ computation did not raise an exception.
- Raises:
- TimeoutError: If a timeout value is passed and the computation does not
- terminate within the allotted time.
- CancelledError: If the computation was cancelled.
- """
+ Raises:
+ TimeoutError: If a timeout value is passed and the computation does not
+ terminate within the allotted time.
+ CancelledError: If the computation was cancelled.
+ """
raise NotImplementedError()
@abc.abstractmethod
def add_done_callback(self, fn):
"""Adds a function to be called at completion of the computation.
- The callback will be passed this Future object describing the outcome of
- the computation.
+ The callback will be passed this Future object describing the outcome of
+ the computation.
- If the computation has already completed, the callback will be called
- immediately.
+ If the computation has already completed, the callback will be called
+ immediately.
- Args:
- fn: A callable taking this Future object as its single parameter.
- """
+ Args:
+ fn: A callable taking this Future object as its single parameter.
+ """
raise NotImplementedError()
diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/logging_pool.py b/contrib/python/grpcio/py3/grpc/framework/foundation/logging_pool.py
index 53d2cd00825..a4e140f174d 100644
--- a/contrib/python/grpcio/py3/grpc/framework/foundation/logging_pool.py
+++ b/contrib/python/grpcio/py3/grpc/framework/foundation/logging_pool.py
@@ -27,8 +27,9 @@ def _wrap(behavior):
return behavior(*args, **kwargs)
except Exception:
_LOGGER.exception(
- 'Unexpected exception from %s executed in logging pool!',
- behavior)
+ "Unexpected exception from %s executed in logging pool!",
+ behavior,
+ )
raise
return _wrapping
@@ -50,9 +51,9 @@ class _LoggingPool(object):
return self._backing_pool.submit(_wrap(fn), *args, **kwargs)
def map(self, func, *iterables, **kwargs):
- return self._backing_pool.map(_wrap(func),
- *iterables,
- timeout=kwargs.get('timeout', None))
+ return self._backing_pool.map(
+ _wrap(func), *iterables, timeout=kwargs.get("timeout", None)
+ )
def shutdown(self, wait=True):
self._backing_pool.shutdown(wait=wait)
@@ -61,11 +62,11 @@ class _LoggingPool(object):
def pool(max_workers):
"""Creates a thread pool that logs exceptions raised by the tasks within it.
- Args:
- max_workers: The maximum number of worker threads to allow the pool.
+ Args:
+ max_workers: The maximum number of worker threads to allow the pool.
- Returns:
- A futures.ThreadPoolExecutor-compatible thread pool that logs exceptions
- raised by the tasks executed within it.
- """
+ Returns:
+ A futures.ThreadPoolExecutor-compatible thread pool that logs exceptions
+ raised by the tasks executed within it.
+ """
return _LoggingPool(futures.ThreadPoolExecutor(max_workers))
diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/stream.py b/contrib/python/grpcio/py3/grpc/framework/foundation/stream.py
index 150a22435ee..70ca1d91575 100644
--- a/contrib/python/grpcio/py3/grpc/framework/foundation/stream.py
+++ b/contrib/python/grpcio/py3/grpc/framework/foundation/stream.py
@@ -23,9 +23,9 @@ class Consumer(abc.ABC):
def consume(self, value):
"""Accepts a value.
- Args:
- value: Any value accepted by this Consumer.
- """
+ Args:
+ value: Any value accepted by this Consumer.
+ """
raise NotImplementedError()
@abc.abstractmethod
@@ -37,7 +37,7 @@ class Consumer(abc.ABC):
def consume_and_terminate(self, value):
"""Supplies a value and signals that no more values will be supplied.
- Args:
- value: Any value accepted by this Consumer.
- """
+ Args:
+ value: Any value accepted by this Consumer.
+ """
raise NotImplementedError()