diff --git a/asyncio_extensions.html b/asyncio_extensions.html index 7a489c16b..4ad097fdd 100644 --- a/asyncio_extensions.html +++ b/asyncio_extensions.html @@ -3,19 +3,30 @@ - + server.asyncio_extensions API documentation - + @@ -35,15 +46,56 @@

Module server.asyncio_extensions

Functions

-async def map_suppress(func: Callable[[~T], Coroutine[Any, Any, Any]], iterable: Iterable[~T], logger: logging.Logger = <Logger server.asyncio_extensions (WARNING)>, msg: str = '') +async def map_suppress(func: Callable[[~T], Coroutine[Any, Any, Any]],
iterable: Iterable[~T],
logger: logging.Logger = <Logger server.asyncio_extensions (WARNING)>,
msg: str = '')
+
+ +Expand source code + +
async def map_suppress(
+    func: Callable[[T], Coroutine[Any, Any, Any]],
+    iterable: Iterable[T],
+    logger: logging.Logger = logger,
+    msg: str = ""
+):
+    results = await asyncio.gather(
+        *(func(item) for item in iterable),
+        return_exceptions=True
+    )
+    for result, item in zip(results, iterable):
+        if isinstance(result, BaseException):
+            logger.exception(
+                "Unexpected error %s%s",
+                msg,
+                item,
+                exc_info=result
+            )
+
def synchronized(*args)
+
+ +Expand source code + +
def synchronized(*args):
+    """
+    Ensure that a function will only execute in serial.
+
+    # Params
+    - `lock`: An instance of asyncio.Lock to use for synchronization.
+    """
+    # Invoked like @synchronized
+    if args and inspect.isfunction(args[0]):
+        return _synchronize(args[0])
+
+    # Invoked like @synchronized() or @synchronized(args, ...)
+    return _partial(_synchronize, *args)
+

Ensure that a function will only execute in serial.

Params

    @@ -54,6 +106,26 @@

    Params

    def synchronizedmethod(*args)
    +
    + +Expand source code + +
    def synchronizedmethod(*args):
    +    """
    +    Create a method that will be wrapped with an async lock.
    +
    +    # Params
    +    - `attrname`: The name of the lock attribute that will be used. If the
    +        attribute doesn't exist or is None, a lock will be created. The default
    +        is to use a value based on the decorated function name.
    +    """
    +    # Invoked like @synchronizedmethod
    +    if args and inspect.isfunction(args[0]):
    +        return _synchronize_method(args[0])
    +
    +    # Invoked like @synchronizedmethod() or @synchronizedmethod(args, ...)
    +    return _partial(_synchronize_method, *args)
    +

    Create a method that will be wrapped with an async lock.

    Params

      @@ -72,6 +144,15 @@

      Classes

      (*args, **kwargs)
      +
      + +Expand source code + +
      class AsyncLock(Protocol, AsyncContextManager["AsyncLock"]):
      +    def locked(self) -> bool: ...
      +    async def acquire(self) -> bool: ...
      +    def release(self) -> None: ...
      +

      Base class for protocol classes.

      Protocol classes are defined as::

      class Proto(Protocol):
      @@ -97,15 +178,6 @@ 

      Classes

      def meth(self) -> T: ...
      -
      - -Expand source code - -
      class AsyncLock(Protocol, AsyncContextManager["AsyncLock"]):
      -    def locked(self) -> bool: ...
      -    async def acquire(self) -> bool: ...
      -    def release(self) -> None: ...
      -

      Ancestors

      • typing.Protocol
      • @@ -119,18 +191,36 @@

        Methods

        async def acquire(self) ‑> bool
        +
        + +Expand source code + +
        async def acquire(self) -> bool: ...
        +
        def locked(self) ‑> bool
        +
        + +Expand source code + +
        def locked(self) -> bool: ...
        +
        def release(self) ‑> None
        +
        + +Expand source code + +
        def release(self) -> None: ...
        +
@@ -140,10 +230,6 @@

Methods

(sleep_duration: float = 0.01)
-

An asyncio spinlock. The advantage of using this over asyncio.Lock is that -it can be called accross multiple event loops at the cost of being less -performant. As with any spinlock, it's best used in situations where -concurrent access is unlikely.

Expand source code @@ -189,6 +275,10 @@

Methods

else: raise RuntimeError("Lock is not acquired.")
+

An asyncio spinlock. The advantage of using this over asyncio.Lock is that +it can be called accross multiple event loops at the cost of being less +performant. As with any spinlock, it's best used in situations where +concurrent access is unlikely.

Ancestors