没有项目描述
aioerl的Python项目详细描述
全部
aioerl
是一个python库,它用异步任务模拟erlang进程的原理。
实现以下想法:
- 每个进程都有一个邮箱:从其他进程接收消息的队列。
- 消息传递:进程完全与消息通信(从开发人员的角度来看) 1,进程可以监视其他进程(当进程死亡或崩溃时,以退出原因或异常向其主管发送消息)<
为什么?
asyncio
非常棒,内置的结构如asyncio.Queue
对于任务之间的通信非常有用,但是很难管理错误。
使用aioerl
,进程只需等待来自其他进程的传入消息,并决定如何处理每个事件(请参见example)。
快速启动
要求:python 3.7+
安装:
pip install aioerl
示例
fromaioerlimportspawn_monitored,receive,reply,send,runasyncdefping_pong():whileTrue:m=awaitreceive(timeout=10)ifm.is_ok:ifm.body=="ping":awaitreply("pong")else:raiseException("Invalid message body")elifm.is_timeout:return# terminate processasyncdefmain():p=awaitspawn_monitored(ping_pong())awaitsend(p,"ping")print(awaitreceive())# Message(sender=<ErlProc:2>, event='ok', body='pong')awaitsend(p,"pang")print(awaitreceive())# Message(sender=<ErlProc:2>, event='err', body=Exception("Invalid message body"))awaitsend(p,"ping")print(awaitreceive())# Message(sender=<ErlProc:2>, event='exit', body='noproc')if__name__=="__main__":run(main())
待办事项:
很多事情!