赞
踩
使用python脚本也可以作为windows的服务程序运行
只要下载并安装pywin32模块,就可以很轻松的开发windows服务了
源码如下:
- import win32serviceutil
- import win32service
- import win32event
-
- class test1(win32serviceutil.ServiceFramework):
- _svc_name_ = "python_service"
- _svc_display_name_ = "python_service"
- def __init__(self,args):
- win32serviceutil.ServiceFramework.__init__(self,args)
- self.hWaitStop = win32event.CreateEvent(None,0,0,None)
- pass
- def SvcStop(self):
- self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
- win32event.SetEvent(self.hWaitStop)
- pass
- def SvcDoRun(self):
- win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE)
- pass
- pass
-
- if __name__ == '__main__':
- win32serviceutil.HandleCommandLine(test1)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。