Python異步事件處理框架:Pyeventbus

jopen 10年前發布 | 42K 次閱讀 Python Python開發

Pyeventbus是個十分輕巧的異步事件處理框架。

特性:

  1. Pyeventbus 會檢查你的事件消息類型和偵聽器的類型的合法性,偵聽器和消息需要被正確的創建

  2. 允許一個事件消息有多個對應的處理方法,事件處理的時間復雜度是O(k)的,取決于你的偵聽處理函數有多少個

  3. 支持同步和異步事件處理,可自定義異步事件處理線程池大小

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()

項目主頁:http://www.baiduhome.net/lib/view/home/1408527143397

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!