Alireza Mirzaeiyan Alireza Mirzaeiyan - 4 months ago 97
Python Question

Windows service compile with pyinstaller issue

I've implemented a windows service, this service has no problem before compiling with pyinstaller but after that on service start command it gives 1053 error.

Windows service code:

import sys
import win32service
import win32event
import socket
import win32api
import win32serviceutil


class AppServerSvc(win32serviceutil.ServiceFramework):
_svc_name_ = "test"
_svc_display_name_ = "test"
_stoped = False

def __init__(self, *args):
win32serviceutil.ServiceFramework.__init__(self, *args)
self.stop_event = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
self._stoped = True

def SvcDoRun(self):
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
self.main()

def main(self):
while True:
if self._stoped:
break
pass

if __name__ == '__main__':
win32serviceutil.HandleCommandLine(AppServerSvc)

Answer

Finally i solved this problem, there was a broken link to one of references in windows service. This is the right config for py2exe which solved my problem:

opts = {'py2exe': {
'dll_excludes': ['libzmq.pyd', 'OLEAUT32.dll', 'USER32.dll', 'SHELL32.dll', 'ole32.dll',
                 'MSVCP90.dll', 'ADVAPI32.dll', 'NETAPI32.dll', 'WS2_32.dll', 'GDI32.dll',
                 'VERSION.dll', 'KERNEL32.dll', 'WINSPOOL.DRV', 'mfc90.dll', 'ntdll.dll'],
'includes': ['UserList', 'UserString', 'commands', 'zmq.backend.cython'],
'dist_dir': "dist"
}}

setup(service=[service], options=opts, zipfile=None,data_files=[(os.path.join(os.getcwd(), 'dist'), (zmq.libzmq.__file__,))])