Package: pyeventbus3
pyeventbus3 is a publish/subscribe event bus for Python 3. (Fork of pyeventbus for python 2.7)simplifies the communication between python classesdecouples event senders and receiversperforms well threads, greenlets, queues and concurrent processesavoids complex and error-prone dependencies and life cycle issuesmakes code simplerhas advanced features like delivery threads, workers and spawning different processes, etc.is tiny (3KB archive)pyeventbus3 in 3 steps:Define events:class MessageEvent:
    # Additional fields and methods if needed
    def __init__(self):
        passPrepare subscribers: Declare and annotate your subscribing method, optionally specify a thread mode:from pyeventbus3.pyeventbus3 import *

@subscribe(onEvent=MessageEvent)
def func(self, event):
    # Do something
    passRegister your subscriber. For example, if you want to register a class in Python:from pyeventbus3.pyeventbus3 import *

class MyClass:
    def __init__(self):
        pass

    def register(self, myclass):
        PyBus.Instance().register(myclass, self.__class__.__name__)

# then during initilization

myclass = MyClass()
myclass.register(myclass)Post events:from pyeventbus3.pyeventbus3 import *

class MyClass:
    def __init__(self):
        pass

    def register(self, myclass):
        PyBus.Instance().register(myclass, self.__class__.__name__)

    def postingAnEvent(self):
        PyBus.Instance().post(MessageEvent())

 myclass = MyClass()
 myclass.register(myclass)
 myclass.postingAnEvent()Modes: pyeventbus can run the subscribing methods in 5 different modesPOSTING:Runs the method in the same thread as posted. For example, if an event is posted from main thread, the subscribing method also runs in the main thread. If an event is posted in a seperate thread, the subscribing method runs in the same seperate method

This is the default mode, if no mode has been provided::

@subscribe(threadMode = Mode.POSTING, onEvent=MessageEvent)
def func(self, event):
    # Do something
    passPARALLEL:Runs the method in a seperate python thread::

@subscribe(threadMode = Mode.PARALLEL, onEvent=MessageEvent)
def func(self, event):
    # Do something
    passGREENLET:Runs the method in a greenlet using gevent library::

@subscribe(threadMode = Mode.GREENLET, onEvent=MessageEvent)
def func(self, event):
    # Do something
    passBACKGROUND:Adds the subscribing methods to a queue which is executed by workers::

@subscribe(threadMode = Mode.BACKGROUND, onEvent=MessageEvent)
def func(self, event):
    # Do something
    pass

There is 10 workers by default, see exemple to modify this number.CONCURRENT:Runs the method in a seperate python process::

@subscribe(threadMode = Mode.CONCURRENT, onEvent=MessageEvent)
def func(self, event):
    # Do something
    passAdding pyeventbus to your project:pip install pyeventbus3Example:git clone https://github.com/FlavienVernier/pyeventbus.git

cd pyeventbus

virtualenv venv

source venv/bin/activate

pip install pyeventbus

python example.pyBenchmarks and Performance:Refer /pyeventbus/tests/benchmarks.txt for performance benchmarks on CPU, I/O and networks heavy tasks.

Run /pyeventbus/tests/test.sh to generate the same benchmarks.

Performance comparison between all the modes with Python and CythonInspirationInspired by Eventbus from greenrobot:https://github.com/greenrobot/EventBus