我正在通过正常命令提示符下的python win_service.py install运行下面的代码,在那里我得到访问被拒绝错误.
安装服务TestService
安装服务时出错:访问被拒绝.(5)
当我以管理员身份启动时,我能够解决这个问题.
我能够安装该服务,但我无法启动该服务.
已安装服务
启动服务TestService
启动服务时出错:服务未及时响应启动或控制请求.
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
class AppServerSvc (win32serviceutil.ServiceFramework):
_svc_name_ = "TestService"
_svc_display_name_ = "Test Service"
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None,0,0,None)
socket.setdefaulttimeout(60)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_,''))
self.main()
def main(self):
print "running"
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(AppServerSvc)
Run Code Online (Sandbox Code Playgroud)
出了什么问题,有没有其他方法来安装解决问题的服务以及如何以管理员的身份动态运行它.
所有 python代码服务都可以安装但无法启动
Error 1053: The service did not respond to the start or control request in a timely fashion".
因为我的服务可以在我的服务器上安装和启动.我认为我的代码没有问题.
但我仍然想知道是否有一个解决方案,我可以在代码中解决这个错误
我的服务:
import win32serviceutil
import win32service
import win32event
import time
import traceback
import os
import ConfigParser
import time
import traceback
import os
import utils_func
from memcache_synchronizer import *
class MyService(win32serviceutil.ServiceFramework):
"""Windows Service."""
os.chdir(os.path.dirname(__file__))
conf_file_name = "memcache_sync_service.ini"
conf_parser = ConfigParser.SafeConfigParser()
conf_parser.read(conf_file_name)
_svc_name_, _svc_display_name_, _svc_description_ = utils_func.get_win_service(conf_parser)
def __init__(self, args):
if os.path.dirname(__file__):
os.chdir(os.path.dirname(__file__))
win32serviceutil.ServiceFramework.__init__(self, args)
# create an event that …Run Code Online (Sandbox Code Playgroud)