我是用py2exe exe程序创建的,它使用多处理,工作正常!但是,当我尝试使用win32serviceutil创建Windows服务时,win32service会收到错误 - 无法将其发现为builtin_PYHANDLE。
这是我的代码:
import win32serviceutil
import win32service
import win32event
import servicemanager
from multiprocessing import Process
import time
import datetime
class AppServerSvc (win32serviceutil.ServiceFramework):
_svc_name_ = "Siemens Service Reader"
_svc_display_name_ = "Siemens Service Reader"
_svc_description_ = "__read data from siemens controller 169.254.0.201"
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None,0,0,None)
self.hWaitResume = win32event.CreateEvent(None, 0, 0, None)
self.timeout = 2000
self.resumeTimeout = 2000
self._paused = False
... description of service
... service functions
def SvcDoRun(self):
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_,''))
self.main()
def connect_controller(self):
pass
def connect_controller2(self):
pass
def main(self):
servicemanager.LogInfoMsg("Starting Siemens reader service...")
while True:
p = Process(target= self.connect_controller)
p.start()
p2 = Process(target=self.connect_controller)
p2.start()
p.join()
p2.join()
rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
if rc == win32event.WAIT_OBJECT_0:
servicemanager.LogInfoMsg("Siemens reading is stopping")
if self._paused:
servicemanager.LogInfoMsg("Siemens reading is on pause")
while self._paused:
rc = win32event.WaitForSingleObject(self.hWaitResume, self.resumeTimeout)
if rc == win32event.WAIT_OBJECT_0:
self._paused = False
servicemanager.LogInfoMsg("Yeah! Let's continue!")
break
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(AppServerSvc)
任何人都可以帮忙吗? 如何挑选功能对象?
答案 0 :(得分:0)
如果这不仅仅是一个复制粘贴错误,你(可能)在_svc_description _
的末尾错过"