我試圖啓動一個簡單的服務例如:無法啓動用Python編寫的(win32serviceutil)Windows服務
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旗艦版上運行的Python 2.7.2與pywin32 216與管理privilegies。
這個工作對我來說,運行的Python 2.6.6(64位)和pywin32 216 AMD64的py26。我意識到這不是很有幫助。在Windows 7 Pro上。 – jgritty
+1提的是,錯誤發生1053'如果能pythonservice.exe'找不到'python27.dll'。永遠讓我永遠解決這個問題!謝謝:) – Gili