zoukankan      html  css  js  c++  java
  • 将python的程序包装成windows下的service

      使用python编写的脚本应用程序,在运行的时候需要有python的运行环境,但是我们肯定是希望整个python程序能够像应用程序一样打包生成一个包括其运行环境的exe文件包,这是第一步,但是要想使用net start这样的方式启动, 还需要将该exe注册到服务里面去,使用exe install完成。

     

    #SmallestService.py  
    #AsampledemonstratingthesmallestpossibleservicewritteninPython.  
     
    importwin32serviceutil  
    importwin32service  
    importwin32event  
     
    classSmallestPythonService(win32serviceutil.ServiceFramework):  
        _svc_name_="SmallestPythonService" 
        _svc_display_name_="ThesmallestpossiblePythonService" 
        def__init__(self,args):  
            win32serviceutil.ServiceFramework.__init__(self,args)  
            #Createaneventwhichwewillusetowaiton.  
            #The"servicestop"requestwillsetthisevent.  
            self.hWaitStop=win32event.CreateEvent(None,0,0,None)  
     
      defSvcStop(self):  
         #Beforewedoanything,telltheSCMwearestartingthestopprocess.  
            self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)  
            #Andsetmyevent.  
            win32event.SetEvent(self.hWaitStop)
    
        defSvcDoRun(self):
            #把你的程序代码放到这里就OK了
            win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE)
    
    if__name__=='__main__':
        win32serviceutil.HandleCommandLine(SmallestPythonService)
    

      

  • 相关阅读:
    Oracle分页SQL
    CentOS7下安装Anaconda3
    Alibaba分层领域模型规约
    java的continue标签
    SQLserver 及 redis 无法连接问题
    HTTP状态码
    java命令功能
    sql 查询结果自增序号
    Viewpage实现左右无限滑动
    Android OOM 问题的总结
  • 原文地址:https://www.cnblogs.com/luomingchuan/p/3776113.html
Copyright © 2011-2022 走看看