[python-win32] Pywin32 Windows Service not responding
Mark Hammond
skippy.hammond at gmail.com
Sat Mar 25 23:29:51 EDT 2023
The last pywin32 release was before 3.11 was officially released, so
maybe try either 3.10 or pywin32-306
Mark
On 25/03/2023 7:25 am, jeremy.farmer1206 via python-win32 wrote:
> 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
>
> image.png
>
> 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
>
>
> image.png
>
> Any assistance is very much appreciated!
> Sent with Proton Mail <https://proton.me/> secure email.
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
More information about the python-win32
mailing list