Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rossengeorgiev/gevent-eventemitter
EventEmitter using gevent
https://github.com/rossengeorgiev/gevent-eventemitter
Last synced: 11 days ago
JSON representation
EventEmitter using gevent
- Host: GitHub
- URL: https://github.com/rossengeorgiev/gevent-eventemitter
- Owner: rossengeorgiev
- Created: 2016-02-14T07:47:07.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-01-31T03:17:21.000Z (almost 4 years ago)
- Last Synced: 2024-10-03T12:51:08.600Z (about 1 month ago)
- Language: Python
- Size: 14.6 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
EventEmitter with gevent
~~~~~~~~~~~~~~~~~~~~~~~~|pypi| |coverage| |master_build|
This module implements EventEmitter with gevent.
Installation
============To install the latest release from ``pypi``::
pip install gevent-eventemitter
Usage
=====``EventEmitter`` can be used as mixin, or on it's own. Here is an example as mixin:
.. code:: python
from eventemitter import EventEmitter
class MyClass(EventEmitter):
passinstance = MyClass()
Registering a callback
.. code:: python
def do_stuff():
print "Hello world!"instance.on('my event', do_stuff)
instance.emit('my event')
Or as decorator
.. code:: python
@instance.on('my event')
def do_stuff():
print "Hello world!"With ``once`` the callback will be called, you guessed it, only once.
.. code:: python
@instance.once('my event')
def do_stuff(var):
print "Hello %s!" % varinstance.emit('my event', 'Earth') # arguments can be passed along events
instance.emit('my event') # do_stuff won't be calledIt's possible to block wait for an event.
If there are event arguments they will be returned as a ``tuple``.. code:: python
my_args = instance.wait_event('my event')
my_args = instance.wait_event('my event', timeout=5) # wait at most 5secondsOn timeout ``wait_event`` will return ``None``, or raise ``gevent.Timeout`` if ``raises=True``
.. code:: python
my_args = instance.wait_event('my event', timeout=5)
if my_args is None:
print "Timeout!"try:
my_args = instance.wait_event('my event', timeout=5, raises=True)
except gevent.Timeout:
print "Timeout!"To remove a callback, or all callbacks.
.. code:: python
instance.remove_listener('my event', do_stuff)
instance.remove_all_listeners() # absolutely all listeners
instance.remove_all_listeners('my event') # all listners for the eventListening for ``None`` event will result in catching all events.
.. |pypi| image:: https://img.shields.io/pypi/v/gevent-eventemitter.svg?style=flat&label=latest%20version
:target: https://pypi.python.org/pypi/gevent-eventemitter
:alt: Latest version released on PyPi.. |coverage| image:: https://img.shields.io/coveralls/rossengeorgiev/gevent-eventemitter/master.svg?style=flat
:target: https://coveralls.io/r/rossengeorgiev/gevent-eventemitter?branch=master
:alt: Test coverage.. |master_build| image:: https://github.com/rossengeorgiev/gevent-eventemitter/workflows/Tests/badge.svg?branch=master
:target: https://github.com/rossengeorgiev/gevent-eventemitter/actions?query=workflow%3A%22Tests%22+branch%3Amaster
:alt: Build status of master branch