'''python
import win32service
import win32serviceutil
import win32event
import os, time
import winerror
class service(win32serviceutil.ServiceFramework):
_svc_name_ = 'service'
_svc_display_name_ = 'service'
_svc_description_ = 'service'
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
self.isAlive = True
def SvcDoRun(self):
while self.isAlive:
print('do something')
time.sleep(2)
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
self.isAlive = False
if name == '__main__':
import sys
import servicemanager
if len(sys.argv) == 1:
try:
evtsrc_dll = os.path.abspath(servicemanager.__file__)
servicemanager.PrepareToHostSingle(service)
servicemanager.Initialize('service', evtsrc_dll)
servicemanager.StartServiceCtrlDispatcher()
except win32service.error as details:
import winerror
if details == winerror.ERROR_FAILED_SERVICE_CONTROLLER_CONNECT:
win32serviceutil.usage()
else:
win32serviceutil.HandleCommandLine(service)
'''
服务能安装,但是启动就显示如题的错误,代码我也debug过,能输入run里面那句话。然后我查看windows事件查看器,有两条错误启动的记录。
另一条记录:
弄了好久怎么也搞不定。特来请教各位
个人也遇到这个问题,
先确定服务:可执行文件的路径:
"xxxxxPython36libsite-packageswin32PythonService.exe"
PythonService.exe是否能运行,若能说明没有xxx.dll动态库问题。
配置python path不能设置在user下,应该设置在system path下就可以了,参考下面的说明:
https://stackoverflow.com/questions/8943371/cant-start-windows-service-written-in-python-win32serviceutil
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.
个人的这个问题是这样解决的。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。