[python-win32] Pywin32 Windows Service not responding
Steven Manross
steven at manross.net
Sat Mar 25 20:49:31 EDT 2023
Something seems to be stripping your code at about 40-50 characters and it seems like we are missing the right half of your code.
Example:
_svc_description_ = 'This is a sample Python Wind
Steven
From: python-win32 <python-win32-bounces+steven=manross.net at python.org> On Behalf Of jeremy.farmer1206 via python-win32
Sent: Friday, March 24, 2023 1:26 PM
To: python-win32 at python.org
Subject: [python-win32] Pywin32 Windows Service not responding
Hi, I am looking for some assistance with utilizing pywin32 in order to create a Windows Service.
I've tried to create as bare-bones of an application as I could inheriting from win32serviceutil.ServiceFramework
import traceback
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import time
import os
import sys
class MyService(win32serviceutil.ServiceFramework):
_svc_name_ = 'MyPythonService'
_svc_display_name_ = 'My Python Service'
_svc_description_ = 'This is a sample Python Wind
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(se
self.hWaitStop = win32event.CreateEvent(None,
socket.setdefaulttimeout(60)
self.is_alive = True
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE
win32event.SetEvent(self.hWaitStop)
self.is_alive = False
def SvcDoRun(self):
self.ReportServiceStatus(win32service.SERVICE
self.ReportServiceStatus(win32service.SERVICE
# win32event.WaitForSingleObject(self.hWaitSt
try:
servicemanager.LogMsg(servicemanager.EVEN
PYS_SERVICE_STARTED, (self._svc_name_, ''))
self.main()
except Exception as ex:
servicemanager.LogErrorMsg("Exception in
eback.format_exc()))
raise
def main(self):
while self.is_alive:
with open('test.txt', 'a') as f:
f.write('Service loop...')
time.sleep(2)
if __name__ == '__main__':
if len(sys.argv) == 1:
servicemanager.Initialize()
servicemanager.PrepareToHostSingle(MyService)
servicemanager.StartServiceCtrlDispatcher()
else:
win32serviceutil.HandleCommandLine(MyService)
I've installed it via opening an admin command prompt and running
python main.py install
It installs successfully but if I attempt to run it, I get
[cid:image001.png at 01D95F42.26DA6EF0]
Or
>python main.py<http://main.py> start
Starting service MyPythonService
Error starting service: The service did not respond to the start or control request in a timely fashion.
debugging seems to work, or at least does not give any errors
python main.py<http://main.py> debug
Debugging service MyPythonService - press Ctrl+C to stop.
Info 0x40001002 - The MyPythonService service has started.
I believe my pywin32 is fully up to date
python -m pip install --upgrade pywin32
Requirement already satisfied: pywin32 in c:\users\jerem\appdata\local\programs\python\python311\lib\site-packages (305)
Misc
python --version
Python 3.11.2
[cid:834fd2a at proton.me]
Any assistance is very much appreciated!
Sent with Proton Mail<https://proton.me/> secure email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-win32/attachments/20230326/dfb5326b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 7142 bytes
Desc: image001.png
URL: <https://mail.python.org/pipermail/python-win32/attachments/20230326/dfb5326b/attachment-0001.png>
More information about the python-win32
mailing list