- Replace open/write/flush/close per log call with persistent file handle - Use threading.Queue + background daemon thread for non-blocking writes - Only flush on exception/critical levels or periodically (every 1s idle) - Queue full protection: drop oldest entry instead of blocking event loop - Eliminates disk I/O blocking on slow storage (NFS/cloud disk) during high traffic
appPublic
a set of icommon modules for python development
EventDispatcher
生产级异步事件调度器。
特性
- 支持普通函数
- 支持 async 协程
- 支持实例方法
- 弱引用自动GC
- 异常隔离
- 超时控制
- 自定义错误处理
使用示例
import asyncio
from event_dispatcher import EventDispatcher
def on_login(data):
print(data)
async def main():
dispatcher = EventDispatcher()
dispatcher.bind(
"login",
on_login
)
await dispatcher.dispatch(
"login",
{
"user": "张三"
}
)
asyncio.run(main())
Description
Languages
Python
97.5%
Shell
2.5%