我正在尝试将python中的一个项目作为windows服务运行。它可以作为前台进程和服务运行。当我们把它作为前台进程运行时,一切都很好。但是当我们将它作为服务运行时,它会给一个甚至被前台进程使用的文件配置文件的权限拒绝错误。 是的,我以管理员的身份运行它。 以下是windows服务的代码:
# Python script to run tevico_scanner as a windows service
# We are using pywin32 python extension modules for windows.
import servicemanager
import win32event
import win32service
import win32serviceutil
from tevico_scanner import constants
from tevico_scanner import watchman
class WindowsService(win32serviceutil.ServiceFramework):
# Service name that we use to start/stop the service
_svc_name_ = "<service_name>"
# Service Display Name
_svc_display_name_ = "<service_display_name>"
# Description for our scanner
_svc_service_description_ = "<description>"
config_file = constants.DEFAULT_CFG_FILE
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.wman = watchman.Watchman(self.config_file)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcDoRun(self):
# Run our watchman
watchman._CW_FLAG = False
watchman._DEBUGGING = False
self.wman.run()
def SvcDoStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(WindowsService)
错误消息:
^{pr2}$谢谢。在
目前没有回答
相关问题 更多 >
编程相关推荐