免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1483 | 回复: 2
打印 上一主题 下一主题

请教一个用win32库写deamon的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-02-28 09:33 |只看该作者 |倒序浏览
我写了一个wmi的监控想放到后台运行,用win32库的一个模板,但是在运行的时候可以安装服务,但是却启动不了服务
cmd 执行 win_deamon.py install 没有问题,执行win_deamon.py start就不行了,有人知道怎么解决吗?
执行win_deamon.py debug 也没有问题
代码是如下 Powershell是我写的模块命名
#!/usr/bin/python
# -*- coding: utf-8 -*-
import win32serviceutil
import win32service
import win32event
import powershell
class SmallestPythonService(win32serviceutil.ServiceFramework):
    _svc_name_ = "Disk Monitor Service"
    _svc_display_name_ = "The smallest possible Python Service"
    def __init__(self, args):
        self.threads = []
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)
    def SvcDoRun(self):
        #This is my program !
        powershell.demo()
        self.threads = []
        win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
if __name__=='__main__':
    win32serviceutil.HandleCommandLine(SmallestPythonService)

论坛徽章:
0
2 [报告]
发表于 2015-02-28 09:58 |只看该作者
最终自己找到了解决方案...
把python的path添加到系统的环境变量就可以了,原文如下
What you need to do is to add the Python27 to SYSTEM PATH, and not to USER PATH, since as a default the python service will get installed as a 'LocalSystem' and so when it attempts to start it uses the SYSTEM PATH variable - that's why you can run it from the command prompt, your USER PATH is right.

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:56:11
3 [报告]
发表于 2015-02-28 10:40 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP