后台小程序开发的全方位指南
589
2022-10-17
oi-有 CLI 界面的,可长期运行的应用进程编辑框架
oi
python library for writing long running processes with a cli interface
Install
Note: You need nanomsg installed on your system:
$ git clone git@github.com:nanomsg/nanomsg.git$ cd nanomsg$ ./configure$ make$ make check$ sudo make install
Then install oi
$ pip install oi
Usage
####1. Write your long running program
# programd.pyimport oiprogram = 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. Add a ctl interface
# programctl.pyimport oictl = oi.CtlProgram('ctl program', address='ipc:///tmp/program.sock')ctl.run()
####3. Run program, then connect to it via ctl
# Run process$ python programd# OR with a configuration file$ python programd --config /etc/program.conf$ python programctl # enter ctl loopprogramctl > pingpong# OR ping end exit$ python programctl ping
Quickly get started with a new project
$ mkdir xprogram$ cd xprogram$ oi init$ make install# Start your program$ xprogramd# Start ctl program$ xprogramctlctl > pingpong# Upload to pypi (Edit setup.py before distributing)$ make distribute
Now the interesting bit. Are you ready?
Run your program on one computer, then control it from another with a single line change (actually two).
Just change the address ipc:///tmp/program.sock to a tcp address, such as tcp://192.168.1.100:5000 in both your programd.py and programctl.py. That's it! (:
TODO
Add more testing
License
MIT License
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~