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):
pass
instance = 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!" % var
instance.emit('my event', 'Earth') # arguments can be passed along events
instance.emit('my event') # do_stuff won't be called
It'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 5seconds
On 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 event
Listening 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://img.shields.io/travis/rossengeorgiev/gevent-eventemitter/master.svg?style=flat&label=master%20build
:target: http://travis-ci.org/rossengeorgiev/gevent-eventemitter
:alt: Build status of master branch
Raw data
{
"_id": null,
"home_page": "https://github.com/rossengeorgiev/gevent-eventemitter",
"name": "gevent-eventemitter",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "gevent event emitter ee greenlet",
"author": "Rossen Georgiev",
"author_email": "rossen@rgp.io",
"download_url": "https://files.pythonhosted.org/packages/1f/56/9e449b380f1e8cf19bedb4564e61a79dcf3971e6204ef08885d5816a9fe9/gevent-eventemitter-2.1.tar.gz",
"platform": "",
"description": "EventEmitter with gevent\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n|pypi| |coverage| |master_build|\n\nThis module implements EventEmitter with gevent.\n\nInstallation\n============\n\nTo install the latest release from ``pypi``::\n\n pip install gevent-eventemitter\n\nUsage\n=====\n\n``EventEmitter`` can be used as mixin, or on it's own. Here is an example as mixin:\n\n.. code:: python\n\n from eventemitter import EventEmitter\n\n class MyClass(EventEmitter):\n pass\n\n instance = MyClass()\n\n\nRegistering a callback\n\n.. code:: python\n\n def do_stuff():\n print \"Hello world!\"\n\n instance.on('my event', do_stuff)\n\n instance.emit('my event')\n\nOr as decorator\n\n.. code:: python\n\n @instance.on('my event')\n def do_stuff():\n print \"Hello world!\"\n\nWith ``once`` the callback will be called, you guessed it, only once.\n\n.. code:: python\n\n @instance.once('my event')\n def do_stuff(var):\n print \"Hello %s!\" % var\n\n instance.emit('my event', 'Earth') # arguments can be passed along events\n instance.emit('my event') # do_stuff won't be called\n\nIt's possible to block wait for an event.\n If there are event arguments they will be returned as a ``tuple``\n\n.. code:: python\n\n my_args = instance.wait_event('my event')\n my_args = instance.wait_event('my event', timeout=5) # wait at most 5seconds\n\nOn timeout ``wait_event`` will return ``None``, or raise ``gevent.Timeout`` if ``raises=True``\n\n.. code:: python\n\n my_args = instance.wait_event('my event', timeout=5)\n if my_args is None:\n print \"Timeout!\"\n\n try:\n my_args = instance.wait_event('my event', timeout=5, raises=True)\n except gevent.Timeout:\n print \"Timeout!\"\n\nTo remove a callback, or all callbacks.\n\n.. code:: python\n\n instance.remove_listener('my event', do_stuff)\n instance.remove_all_listeners() # absolutely all listeners\n instance.remove_all_listeners('my event') # all listners for the event\n\nListening for ``None`` event will result in catching all events.\n\n\n.. |pypi| image:: https://img.shields.io/pypi/v/gevent-eventemitter.svg?style=flat&label=latest%20version\n :target: https://pypi.python.org/pypi/gevent-eventemitter\n :alt: Latest version released on PyPi\n\n.. |coverage| image:: https://img.shields.io/coveralls/rossengeorgiev/gevent-eventemitter/master.svg?style=flat\n :target: https://coveralls.io/r/rossengeorgiev/gevent-eventemitter?branch=master\n :alt: Test coverage\n\n.. |master_build| image:: https://img.shields.io/travis/rossengeorgiev/gevent-eventemitter/master.svg?style=flat&label=master%20build\n :target: http://travis-ci.org/rossengeorgiev/gevent-eventemitter\n :alt: Build status of master branch\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Implements EventEmitter using gevent",
"version": "2.1",
"split_keywords": [
"gevent",
"event",
"emitter",
"ee",
"greenlet"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "996ed5368dd734dc2a55beef9c071a5f",
"sha256": "30605a9fbb1f38b2511f188a2e7a1b4e9262f3c13bf810ac5b79cc0ba2900ff7"
},
"downloads": -1,
"filename": "gevent_eventemitter-2.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "996ed5368dd734dc2a55beef9c071a5f",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 5863,
"upload_time": "2019-06-02T10:01:31",
"upload_time_iso_8601": "2019-06-02T10:01:31.926288Z",
"url": "https://files.pythonhosted.org/packages/c7/f5/47f896511ca1fb5dd6e9fa1ba152f9ccc3f892f4d31c8757cfe36c248c8e/gevent_eventemitter-2.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "45b50814265d14369635a1cb6a8ee628",
"sha256": "00e6e688c6a255f7bdcef1d8c999e0d02d9ab87d3c6ff626e6dc1a09762107f4"
},
"downloads": -1,
"filename": "gevent-eventemitter-2.1.tar.gz",
"has_sig": false,
"md5_digest": "45b50814265d14369635a1cb6a8ee628",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3725,
"upload_time": "2019-06-02T10:01:33",
"upload_time_iso_8601": "2019-06-02T10:01:33.479008Z",
"url": "https://files.pythonhosted.org/packages/1f/56/9e449b380f1e8cf19bedb4564e61a79dcf3971e6204ef08885d5816a9fe9/gevent-eventemitter-2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2019-06-02 10:01:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "rossengeorgiev",
"github_project": "gevent-eventemitter",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [
{
"name": "gevent",
"specs": [
[
">=",
"1.3"
]
]
}
],
"lcname": "gevent-eventemitter"
}