Home > other >  Python service packaging issues
Python service packaging issues

Time:10-01

Did a Windows service in python,

The main structure is as follows:
The class Smonitoringdebug () : svc_name="Smonitoringdebug"
Svc_display_name="Smonitoringdebug"
Svc_description="monitoring test"
Def SvcDoRun (self) :
CNXN=pyodbc. Connect (' DRIVER={SQL Server}; SERVER=test; The DATABASE=Smonitoring; UID=sa; The PWD=1234567 ')
Cursor=CNXN. Cursor ()

Print (" service is the run...
")Try:
While True:
.
Cursor. The execute (... )
MIT ()
cnxn.com
Time. Sleep (100)
CNXN. Close ()
Except the Exception as e:
CNXN. Close ()
Print (e)
Time. Sleep (500)

Def SvcStop (self) :
Print (" service is stop...
")Self. ReportServiceStatus (win32service. SERVICE_STOP_PENDING)
Win32event. SetEvent (self. HWaitStop)
The self. The run=False
If name=='main' :
# win32serviceutil. HandleCommandLine (SmonitoringServer)
Smonitoringdebug (.) SvcDoRun ()

By using normal python environment,

Use pyinstaller package
Pyinstaller Smonitoringdebug. Py

Packaging error after installation services:
SmonitoringServer install
Traceback (the most recent call last) :
The File "SmonitoringServer. Py", line 177, in & lt; module>
The File "site - packages \ win32 \ lib \ win32serviceutil py", line 544, in HandleCommandLine
The File "site - packages \ win32 \ lib \ win32serviceutil py", line 485, in GetServiceClassString
IndexError: list index out of range
[18216] Failed to execute the script SmonitoringServer

Seek the solution, thank you!
  • Related