Skip to main content

Implements EventEmitter using gevent

Project description

Latest version released on PyPi Test coverage Build status of master branch

This module implements EventEmitter with gevent.


To install the latest release from pypi:

pip install gevent-eventemitter


EventEmitter can be used as mixin, or on it’s own. Here is an example as mixin:

from eventemitter import EventEmitter

class MyClass(EventEmitter):

instance = MyClass()

Registering a callback

def do_stuff():
    print "Hello world!"

instance.on('my event', do_stuff)

instance.emit('my event')

Or as decorator

@instance.on('my event')
def do_stuff():
    print "Hello world!"

With once the callback will be called, you guessed it, only once.

@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
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

my_args = instance.wait_event('my event', timeout=5)
if my_args is None:
    print "Timeout!"

    my_args = instance.wait_event('my event', timeout=5, raises=True)
except gevent.Timeout:
    print "Timeout!"

To remove a callback, or all callbacks.

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.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gevent-eventemitter, version 2.1
Filename, size File type Python version Upload date Hashes
Filename, size gevent_eventemitter-2.1-py2.py3-none-any.whl (5.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size gevent-eventemitter-2.1.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page