Skip to content

Commit

Permalink
Try 2
Browse files Browse the repository at this point in the history
  • Loading branch information
marbx committed Sep 18, 2021
1 parent 8695d10 commit ad2a879
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
27 changes: 18 additions & 9 deletions python_service_by_wix/Python_service_by_pywin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
import win32event
import servicemanager
import socket



import sys

class AppServerSvc (win32serviceutil.ServiceFramework):
_svc_name_ = "Python_service_by_pywin32"
_svc_display_name_ = "Python_service_by_pywin32"
STRFTIME = '%Y-%m-%dT%H:%M:%S'
run = 0
_svc_name_ = "TestService"
_svc_display_name_ = "Test Service"

def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
Expand All @@ -28,12 +24,14 @@ def SvcDoRun(self):
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_,''))
#self.main()
self.main()


def main(self):
import time
import datetime
STRFTIME = '%Y-%m-%dT%H:%M:%S'
run = 0

while self.run < 900:
self.run += 1
Expand All @@ -43,5 +41,16 @@ def main(self):
f.write(f"{now}\n")
time.sleep(5)


if __name__ == '__main__':
win32serviceutil.HandleCommandLine(AppServerSvc)
if len(sys.argv) > 1:
# Called by Windows shell. Handling arguments such as: Install, Remove, etc.
win32serviceutil.HandleCommandLine(AppServerSvc)
else:
# Called by Windows Service. Initialize the service to communicate with the system operator
servicemanager.Initialize()
servicemanager.PrepareToHostSingle(AppServerSvc)
servicemanager.StartServiceCtrlDispatcher()



26 changes: 26 additions & 0 deletions python_service_by_wix/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@

## Try 2


https://stackoverflow.com/questions/41200068/python-windows-service-error-starting-service-the-service-did-not-respond-to-t

```
Python \Python39\Scripts\pywin32_postinstall.py -install
pip install pyinstaller
pyinstaller --noconfirm Python_service_by_pywin32.py
dist\Python_service_by_pywin32>Python_service_by_pywin32.exe
Traceback (most recent call last):
File "C:\git\LearnWix3\python_service_by_wix\Python_service_by_pywin32.py", line 56, in <module>
servicemanager.StartServiceCtrlDispatcher()
pywintypes.error: (1063, 'StartServiceCtrlDispatcher', 'The service process could not connect to the service controller.')
[8020] Failed to execute script Python_service_by_pywin32
```

## Try 1

```
pip install pywin32
Expand Down
3 changes: 3 additions & 0 deletions python_service_by_wix/clean.cmd
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
PowerShell -ExecutionPolicy RemoteSigned -File clean.ps1
rmdir /s /q build dist __pycache__
del Python_service_by_pywin32.spec

0 comments on commit ad2a879

Please sign in to comment.