Python异步事件处理框架:Pyeventbus
jopen
10年前
Pyeventbus是个十分轻巧的异步事件处理框架。
特性:
-
Pyeventbus 会检查你的事件消息类型和侦听器的类型的合法性,侦听器和消息需要被正确的创建
-
允许一个事件消息有多个对应的处理方法,事件处理的时间复杂度是O(k)的,取决于你的侦听处理函数有多少个
-
支持同步和异步事件处理,可自定义异步事件处理线程池大小
Example
.. code-block:: python
from eventbus.eventbus import EventBus #now create a eventbus,the default pool size is 4 and isdaemon is true eventbus=EventBus()
.. code-block:: python
#add the listener to eventbus so it will use the right handler to process the event eventbus.register(Listener())
.. code-block:: python
#now the event message were sent,eventbus will process #this is for the async post eventbus.async_post(GreetEvent()) #this is for the sync post eventbus.post(GreetEvent())
.. code-block:: python
#remove the listener eventbus.unregister(Listener())
.. code-block:: python
#destroy the eventbus eventbus.destroy()