pydispatch.aioutils¶
AioWeakMethodContainer class¶
- class AioWeakMethodContainer[source]¶
Bases:
WeakMethodContainerStorage for coroutine functions as weak references
Added in version 0.1.0.
- __call__(*args, **kwargs)[source]¶
Triggers all stored callbacks (coroutines)
- Parameters:
*args – Positional arguments to pass to callbacks
**kwargs – Keyword arguments to pass to callbacks
- add_method(callback, loop: AbstractEventLoop | None = None, **kwargs)[source]¶
Add a coroutine function
- Parameters:
callback – The coroutine function to add
loop – The
event loopinstance on which to schedule callbacks. This argument is required.
Important
The positional arguments are now
callback, loop, rather thanloop, callback. Calls using both keywords are unchanged.Changed in version 0.3.0: Reordered the arguments and accepted extra keyword arguments.
- iter_methods()[source]¶
Iterate over stored coroutine functions
- Yields:
Stored coroutine function objects
- submit_coroutine(coro, loop)[source]¶
Schedule and await a coroutine on the specified loop
The coroutine is wrapped and scheduled using
asyncio.run_coroutine_threadsafe(). While the coroutine is “awaited”, the result is not available as method returns immediately.- Parameters:
coro – The coroutine to schedule
loop – The
event loopon which to schedule the coroutine
Note
This method is used internally by
__call__()and is not meant to be called directly.
AioEventWaiters class¶
- class AioEventWaiters[source]¶
Container used to manage
awaituse with eventsUsed by
pydispatch.dispatch.Eventwhen it isawaited- waiters¶
Instances of
AioEventWaitercurrently “awaiting” the event- Type:
Added in version 0.1.0.
- __call__(*args: object, **kwargs: object) None[source]¶
Triggers any stored
waitersCalls
AioEventWaiter.trigger()method on all instances stored inwaiters. After completion, thewaitersare removed.- Parameters:
*args – Positional arguments to pass to
AioEventWaiter.trigger()**kwargs – Keyword arguments to pass to
AioEventWaiter.trigger()
- async add_waiter() AioEventWaiter[source]¶
Add a
AioEventWaiterto thewaiterscontainerThe event loop to use for
AioEventWaiter.loopis found in the current context usingasyncio.get_event_loop()- Returns:
The created
AioEventWaiterinstance- Return type:
waiter
- async wait() tuple[list[object] | tuple[object, ...], dict[str, object]][source]¶
Creates a
waiterand “awaits” its resultThis method is used by
pydispatch.dispatch.Eventinstances when they are “awaited” and is the primary functionality ofAioEventWaitersandAioEventWaiter.- Returns:
A two-tuple
(args, kwargs)containing the positional and keyword arguments from the dispatchedEvent.argsis a tuple, andkwargsis a dictionary. If the waiter’s event is set without triggering it,argsremains the initial empty list andkwargsremains empty.
AioEventWaiter class¶
- class AioEventWaiter(loop: AbstractEventLoop)[source]¶
Stores necessary information for a single “waiter”
Used by
AioEventWaitersto handleawaitinganEventon a specificevent loop- aio_event¶
An
asyncio.Eventused to track event emission
- args¶
The positional arguments attached to the event. Initially an empty list; after a trigger, a tuple of arguments.
Added in version 0.1.0.
- trigger(*args: object, **kwargs: object) None[source]¶
Called on event emission and notifies the
wait()methodCalled by
AioEventWaiterswhen theEventinstance is dispatched.Positional and keyword arguments are stored as instance attributes for use in the
wait()method andaio_eventis set.
AioSimpleLock class¶
- class AioSimpleLock[source]¶
asyncio.Lockalternative backed by athreading.LockThis is a context manager that supports use in both
withandasync withcontext blocks.- lock¶
Instance of
threading.Lock
Added in version 0.1.0.
- acquire(blocking=True, timeout=-1)[source]¶
Acquire the
lock- Parameters:
blocking (bool) – See
threading.Lock.acquire()timeout (float) – See
threading.Lock.acquire()
- Returns:
- Return type: