pydispatch.aioutils module¶
AioWeakMethodContainer class¶
-
class
AioWeakMethodContainer[source]¶ Bases:
pydispatch.utils.WeakMethodContainerStorage for coroutine functions as weak references
New 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(loop, callback)[source]¶ Add a coroutine function
Parameters: - loop – The
event loopinstance on which to schedule callbacks - callback – The coroutine function to add
- loop – The
-
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¶ set – Instances of
AioEventWaitercurrently “awaiting” the event
-
lock¶ AioSimpleLock – A sync/async lock to guard modification to the
waiterscontainer during event emission
New in version 0.1.0.
-
__call__(*args, **kwargs)[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()
- *args – Positional arguments to pass to
-
add_waiter()[source]¶ Add a
AioEventWaiterto thewaiterscontainerThe event loop to use for
AioEventWaiter.loopis found in the current context usingasyncio.get_event_loop()Returns: The created AioEventWaiterinstanceReturn type: waiter
-
wait()[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: Positional arguments attached to the event kwargs (dict): Keyword arguments attached to the event Return type: args (list)
-
AioEventWaiter class¶
-
class
AioEventWaiter(loop)[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¶ list – The positional arguments attached to the event
-
kwargs¶ dict – The keyword arguments attached to the event
New in version 0.1.0.
-
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
New in version 0.1.0.
-
acquire(blocking=True, timeout=-1)[source]¶ Acquire the
lockParameters: - blocking (bool) – See
threading.Lock.acquire() - timeout (float) – See
threading.Lock.acquire()
Returns: Return type: - blocking (bool) – See
-