Tôi đang cố gắng để bắt đầu một ví dụ dịch vụ đơn giản:Không thể bắt đầu dịch vụ Windows được viết bằng Python (win32serviceutil)
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)
Khi tôi chạy
python someservice.py install
mọi thứ đều ổn và dịch vụ xuất hiện trong danh sách dịch vụ Windows, nhưng
python someservice.py start
không thành công với "Lỗi 1053: Dịch vụ không phản hồi yêu cầu bắt đầu hoặc kiểm soát kịp thời", nhưng không có bất kỳ sự chậm trễ nào.
Tôi googled một giải pháp, cho biết điều đó xảy ra khi pythonservice.exe
không thể định vị python27.dll
. Nó thực sự không thể vì vậy tôi đã thêm C:\Python27
đến PATH
. Bây giờ pythonservice.exe
chạy tốt, nhưng Lỗi 1053 vẫn còn ở đó.
Tôi đang chạy Python 2.7.2 với pywin32 216 trên Windows 7 Ultimate với đặc quyền quản trị viên.
Điều này làm việc cho tôi, chạy Python 2.6.6 (64 bit) và pywin32 216 amd64-py26. Tôi nhận ra rằng đó không phải là rất hữu ích mặc dù. Trên Windows 7 Pro. – jgritty
+1 để đề cập đến lỗi 1053 xảy ra nếu 'pythonservice.exe' không thể định vị' python27.dll'. Đưa tôi mãi mãi để tìm ra điều này! Cảm ơn :) – Gili