Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2644353
  • 博文数量: 416
  • 博客积分: 10220
  • 博客等级: 上将
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-15 09:47
文章分类

全部博文(416)

文章存档

2022年(1)

2021年(1)

2020年(1)

2019年(5)

2018年(7)

2017年(6)

2016年(7)

2015年(11)

2014年(1)

2012年(5)

2011年(7)

2010年(35)

2009年(64)

2008年(48)

2007年(177)

2006年(40)

我的朋友

分类: Python/Ruby

2018-07-06 15:24:15

遇到与它相同的问题
本来已经在它的问题下面回答了,但答复没有显示,在此记录一下。同时也借用它的图片文字:

'''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事件查看器,有两条错误启动的记录。


解决参考:
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.

把python path环境变量由user path 改为system path即可


阅读(2015) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~