异步多进程日志记录

logbook-aiopipe的Python项目详细描述


logbook_aioppe—异步多进程日志记录

Documentation

此包为多进程提供处理程序和订阅服务器 ^{}^{}事件循环。它使用 ^{}从子级传输日志消息 进程到父进程。

示例

下面的示例显示了多进程日志记录的典型应用程序。结果是 两条日志消息,hello from parent processhello from child process,是 按顺序打印。

fromcontextlibimportclosingfrommultiprocessingimportProcessimportasynciofromaiopipeimportaiopipefromlogbook_aiopipeimportAioPipeSubscriber, \
        AioPipeHandlerfromlogbookimportLogger,StderrHandlerasyncdefmainTask(eventLoop):# The parent process logger can be set up as normal.log=Logger()log.handlers.append(StderrHandler())rx,tx=aiopipe()sub=AioPipeSubscriber(awaitrx.open(eventLoop),log)withclosing(sub):subTask=eventLoop.create_task(sub.run())withtx.send()astx:proc=Process(target=childProc,args=(tx,))proc.start()log.info("hello from parent process")proc.join()awaitsubTaskdefchildProc(tx):eventLoop=asyncio.new_event_loop()eventLoop.run_until_complete(childTask(eventLoop,tx))asyncdefchildTask(eventLoop,tx):log=Logger()# The child process should use only `AioPipeHandler` as# its handler.handler=AioPipeHandler(awaittx.open(eventLoop))log.handlers.append(handler)withclosing(handler):log.info("hello from child process")eventLoop=asyncio.get_event_loop()eventLoop.run_until_complete(mainTask(eventLoop))

安装

此软件包要求python>;=3.5.0,可以使用pip

安装
pip install logbook_aiopipe

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java泛型和基类   ProcessBuilder或DefaultExecutor启动的“RunAs”子进程的java读取标准输出   java应用程序在尝试登录时突然停止   Java:神秘的Java未捕获异常处理程序[带代码]   java JavaFX NumberAxis自动范围无限循环   最新版本和旧版本冲突的java双Maven依赖关系   java如何导入带有部署变量类名的静态函数?   编译器构造不同的JDK更新会产生不同的Java字节码吗?   java无法在struts 1.1中上载任何超过250 MB大小的文件   java调整jcombobox下拉菜单的宽度   java如何在某些情况下忽略@SQLDelete注释   在Eclipse for Java EE developers edition中禁用HTML警告   java HttpUrlConnection重置请求属性   java@Provider资源未在rest应用程序中注册   java TOP N使用JPA连接   java在使用反射调用方法时区分int和Integer参数