Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neeky/shortcoding
python 编程中常用逻辑的高度封装
https://github.com/neeky/shortcoding
Last synced: 23 days ago
JSON representation
python 编程中常用逻辑的高度封装
- Host: GitHub
- URL: https://github.com/neeky/shortcoding
- Owner: Neeky
- Created: 2019-04-06T07:03:45.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-06T08:16:58.000Z (almost 6 years ago)
- Last Synced: 2024-12-07T21:51:34.497Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## shortcoding
**简化 python 代码是 shortcoding 是唯一目的,shotcoding: 没有什么是一个 import 解决不了的.**---
## 让程序以守护进程方式运行
**start_daemon 让程序以守护进程方式运行**
```python
#!/usr/bin/env python3
import time
import argparse
from shortcoding.daemon import start_daemon,stop_daemondef main():
"""业务逻辑代码
"""
while True:
# 假设这是一套非常赚钱的业务
time.sleep(1)if __name__ == "__main__":
parser = argparse.ArgumentParser("daemon")
parser.add_argument('action',choices=('stop','start'),help="start or stop daemon")
parser.add_argument('--pid-file',default='/tmp/shortcoding.pid',help='pid file')
args = parser.parse_args()
if args.action == 'start':
start_daemon(args.pid_file) # 一行代码程序就可以以守护进程的方式运行了
main()
else:
stop_daemon(args.pid_file)
```