Re: [python-win32] Pywin32 Windows Service not responding

2023-03-25 Thread Mark Hammond
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  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  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  secure email.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Pywin32 Windows Service not responding

2023-03-25 Thread Steven Manross
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  On 
Behalf Of jeremy.farmer1206 via python-win32
Sent: Friday, March 24, 2023 1:26 PM
To: python-win32@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@01D95F42.26DA6EF0]

Or

>python 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 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@proton.me]

Any assistance is very much appreciated!
Sent with Proton Mail secure email.
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Pywin32 Windows Service not responding

2023-03-25 Thread jeremy.farmer1206 via python-win32
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 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 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@python.org
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] [ANN] pywin32 build 306 released

2023-03-25 Thread Mark Hammond

Hi all,
I'm happy to announce the release of pywin32 build 306. There are 
relatively few changes in this release:


 * Support for Python 3.6 was dropped, support for later versions was
   improved.
 * Add GetSystemPowerStatus (#2010, @CristiFati)
 * Add CascadeWindows (#1999, @CristiFati)
 * Add win32gui.ResetDC
 * Fix leak in win32pdh.GetFormattedCounterArray
 * Fix IIS on later python versions (#2025)
 * Fix for service registration code updated in build 305 (#1985)

Downloads are available at:

https://github.com/mhammond/pywin32/releases/tag/b306

and via pypi.

For initial support (eg, to ask questions about the release etc), please 
contact this mailing-list (python-win32@python.org). If you want to 
report a bug, please do so at https://github.com/mhammond/pywin32/issues


As always, thanks to everyone who contributed to this release, both in 
terms of code and reporting bugs - there were a number of new 
contributors which is great to see,


Cheers,

Mark.
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32