【发布时间】:2012-01-20 15:00:41
【问题描述】:
我正在尝试启动一个简单的服务示例:
someservice.py:
import win32serviceutil
import win32service
import win32event
class SmallestPythonService(win32serviceutil.ServiceFramework):
_svc_name_ = "SmallestPythonService"
_svc_display_name_ = "display service"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
if __name__=='__main__':
win32serviceutil.HandleCommandLine(SmallestPythonService)
当我跑步时
python someservice.py install
一切正常,服务出现在 Windows 服务列表中,但是
python someservice.py start
失败并显示“错误 1053:服务未及时响应启动或控制请求”,但没有任何延迟。
我搜索了一个解决方案,它说当pythonservice.exe 找不到python27.dll 时会发生这种情况。实际上不能,所以我将C:\Python27 添加到PATH。现在pythonservice.exe 运行良好,但错误 1053 仍然存在。
我在具有管理员权限的 Windows 7 Ultimate 上运行带有 pywin32 216 的 Python 2.7.2。
【问题讨论】:
-
这对我有用,运行 Python 2.6.6(64 位)和 pywin32 216 amd64-py26。我意识到这不是很有帮助。在 Windows 7 专业版上。
-
+1 表示如果
pythonservice.exe找不到python27.dll会发生错误1053。我花了很长时间才弄清楚这一点!谢谢:)
标签: python windows windows-services pywin32