Python的win32serviceutil之疑似BUG

简介:

郑昀@玩聚SR 20090515

1、现象:

用Python的win32serviceutil控制Windows Service启动、停止、重启时,如下代码一般是没问题的。

import win32serviceutil

def service_manager(action, machine, service):
    if action == 'stop':
        win32serviceutil.StopService(service, machine)
    elif action == 'start':
        win32serviceutil.StartService(service, machine)
    elif action == 'restart':
        win32serviceutil.RestartService(service, machine)
    elif action == 'status':
        if win32serviceutil.QueryServiceStatus(service, machine)[1] == 4:
            print "%s is happy" % service
        else:
            print "%s is being a PITA" % service

但控制Apache Service时,会出现一个很怪的现象。

譬如运行这么简单的语句:

import win32serviceutil

win32serviceutil.StartService("Apache2.2","localhost")

顺利执行后,停止的Apache服务并没有被启动。
此时,Windows事件日志就会报告这种错误:
事件类型:    错误
事件来源:    Apache Service
事件种类:    无
事件 ID:    3299
The Apache service named  reported the following error:
>>> Usage: C:""Apache2.2""bin""httpd.exe [-D name] [-d directory] [-f file]

 

同样,win32serviceutil.RestartService 函数虽然可以先正常地停止掉Apache服务,但试图启动时仍遇到同样的错误。

在多台服务器(Windows2003+SP2)和我本机(WindowsXP+SP2)都可以重现。


2、解决:

 

把machine参数去掉不传即可,或传空字符串。 
即: 
win32serviceutil.StartService("Apache2.2") 

win32serviceutil.StartService("Apache2.2","")

可以正常启动本机的Apache,这样无法遥控域内其他服务器了。

 


3、更多:
1:win32serviceutil.StartService(service, '-w -n "Apache2.2" -k start')
这样不传machine参数,只设定服务启动的传入参数也不行。

2:对于 win32serviceutil.StopService 函数,停止Apache等Windows服务时,不存在此问题。

目录
相关文章
|
5月前
|
数据采集 编解码 JSON
【Python】bug汇总
【Python】bug汇总
121 0
|
4月前
|
Python
0.1+0.2≠0.3,揭秘Python自带的Bug
0.1+0.2≠0.3,揭秘Python自带的Bug
120 0
0.1+0.2≠0.3,揭秘Python自带的Bug
|
4月前
|
Python
python 自带 re bug 推荐使用 regex
python 自带 re bug 推荐使用 regex
32 0
|
6月前
|
Cloud Native Go 开发者
那些年,我们一起追过的Python BUG
那些年,我们一起追过的Python BUG
21 0
|
7月前
|
人工智能 IDE 开发工具
走近Python编程的“BUG”世界
走近Python编程的“BUG”世界
38 0
|
7月前
|
Python
Python Bug分类,及异常处理
Python Bug分类,及异常处理
39 0
|
10月前
|
索引 Python
python基础之字符串、函数、BUG和异常类型介绍及类和对象详细笔记
python基础之字符串、函数、BUG和异常类型介绍及类和对象详细笔记
109 0
|
11月前
|
缓存 Java Python
惊呆了,我的 Python 代码里面出现了薛定谔的 Bug
惊呆了,我的 Python 代码里面出现了薛定谔的 Bug
70 0
|
Python
一个python小测试引发的思考---python-list尽可能少用一些,程序复杂的话,可能出bug
一个python小测试引发的思考---python-list尽可能少用一些,程序复杂的话,可能出bug
112 0
|
小程序 C# Python
【优化】C#小程序集成实现python定时段批量下载电子邮箱附件的bug排除
【优化】C#小程序集成实现python定时段批量下载电子邮箱附件的bug排除
97 0