No project description provided
Project description
Aioevt
Simplified Asyncio Event Management
Problem
Asyncio offers a lot of utilities that provide thread-safe execution of coroutines and synchronous functions. However, there isn't any one "unified" way of emitting/catching events accross threads.
Solution
aioevt - After creating the manager, you can emit 'global' events in a thread-safe way. Callbacks can be both registered and emitted from any thread. This allows you to very easily share objects through multithreaded HTTP servers such as Sanic or Vibora.
Documentation
Create a manager
Register an event
def register(self, name: str, func: Callable, loop: asyncio.AbstractEventLoop=None, recurring: bool=True):
"""
Register a global event to be triggered from a provided event loop when a named event is emitted.
:param name: event name.
:param func: callable function to be called when an event is emitted
:param loop: the loop from which you want the callback to be executed
:param recurring: whether or not the event should be re-registered after it is
"""
Emitting an event
def emit(self, name: str, *args):
"""
Non-blocking function to emit a signal with arbitrary parameters. This can execute both
synchronous or asynchronous callbacks.
:param name: event name
:param args: additional event arguments
:return None
"""
Waiting for an event
@asyncio.coroutine
def wait(self, name: str, timeout: float=None):
"""
Wait until an event fures and return the emit parameters
:param name: Event Name
:param loop: the event loop
:param timeout: the maximum time (in seconds) to wait before it raises an exception
:return the parameters passed to `emit`
:raises asyncio.TimeoutError when necessary
"""
Unregistering an event
def unregister(self, name=None, func=None):
"""
Unregister an event
NOTE: by name is significantly faster than by function since it just needs to do a single lookup.
Unregistering an event via callback means it needs to iterate through ALL events.
:param name: Event name
:param func: callback function
:return None
"""
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aioevt-0.1.1.tar.gz
(3.8 kB
view details)
Built Distribution
aioevt-0.1.1-py3-none-any.whl
(17.1 kB
view details)
File details
Details for the file aioevt-0.1.1.tar.gz
.
File metadata
- Download URL: aioevt-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93778b487dcab3bf8e317409e77387f82f48798caa5080926e03b34d6a27f7be |
|
MD5 | 140449fa8efa3405909df783b741b19c |
|
BLAKE2b-256 | 89417cf02c1f15ad064b4b25d40b4d07581b793f1e4b28b43f6278cd1995f0b7 |
File details
Details for the file aioevt-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: aioevt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 170c3b1c196fc398e3db8bca6246e38f0379e00297200391162ef77e900f78e7 |
|
MD5 | 6f154fc7e6a08b35815d519f77244b11 |
|
BLAKE2b-256 | cc2b64ffc667f62e31f19f432550647ae57f38c4f021d38df9172c551ae00cfd |