使用cli接口编写长时间运行的进程的库
oi的Python项目详细描述
用于使用cli接口编写长时间运行的进程的python库
oi图像
安装
注意:您需要nanomsg 安装在系统上:
$ git clone git@github.com:nanomsg/nanomsg.git
$ cd nanomsg
$ ./configure
$ make
$ make check
$ sudo make install
然后安装oi
$ pip install oi
用法
一。编写长时间运行的程序
# programd.pyimportoiprogram=oi.Program('my program','ipc:///tmp/program.sock')program.add_command('ping',lambda:'pong')program.add_command('state',lambda:program.state)program.run()# program will run forever
2.添加CTL接口
# programctl.pyimportoictl=oi.CtlProgram('ctl program',address='ipc:///tmp/program.sock')ctl.run()
三。运行程序,然后通过ctl
# Run process $ python programd # OR with a configuration file $ python programd --config /etc/program.conf $ python programctl # enter ctl loop programctl > ping pong # OR ping end exit $ python programctl ping
快速启动新项目
$ mkdir xprogram $ cd xprogram $ oi init $ make install # Start your program $ xprogramd # Start ctl program $ xprogramctl ctl > ping pong # Upload to pypi (Edit setup.py before distributing) $ make distribute
有趣的是。你准备好了吗?
在一台计算机上运行程序,然后用 单线变更(实际上是两条)。
只需将地址ipc:///tmp/program.sock更改为TCP地址, 例如programd.py和 programctl.py。就这样!(:
待办事项
- []增加更多测试
许可证
麻省理工学院许可证