李成石

导航

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import time
from oslo_service import service
from oslo_config import cfg
 
class MyService(service.Service):
    def __init__(self, conf=None):
        self.conf = conf
        super(MyService,self).__init__()
 
    def start(self):
        print "service start...."
        time.sleep(2)
        print "service end ...."
 
def main():
    conf = cfg.ConfigOpts() # 服务配置
    server = MyService(conf) # 服务
    launcher = service.launch(conf,server) # 启动服务
    launcher.wait() # 服务启动后进程常驻
 
main()

自定义服务,进程常驻,继承oslo_service 中service.Service类,实现其中start方法,使用service.lauch将进程拉起。上面是定义的一个简单的打印,模拟服务启动过程。

posted on   李成石  阅读(1132)  评论(0编辑  收藏  举报
努力加载评论中...
 
点击右上角即可分享
微信分享提示