For a week now, I’ve been trying to get a Windows service to work that I create from an exe file created by pyinstaller. This is a telegram bot.
But I keep getting error 1053. I have tried several implementations of the Windows service class, changed the ServicePipeTimeout value, but it’s no use. At the same time, in the dubag mod, they all work fine and are initialized without any problems.
One of the implementations:
class BotService(win32serviceutil.ServiceFramework):
_svc_name_ = "Bot"
_svc_display_name_ = "Bot"
_svc_description_ = "Service to run Telegram bot with log archiving."
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
self.loop = None
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
if self.loop:
self.loop.call_soon_threadsafe(self.loop.stop)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, "")
)
# Start logic
check_yesterday_log()
# Run the scheduler in a separate thread
scheduler_thread = Thread(target=schedule_log_cleanup)
scheduler_thread.start()
# Starting a bot
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.loop.run_until_complete(main())
if __name__ == '__main__':
if len(sys.argv) == 1:
servicemanager.Initialize()
servicemanager.PrepareToHostSingle(BotService)
servicemanager.StartServiceCtrlDispatcher()
else:
win32serviceutil.HandleCommandLine(BotService)
I create an exe file with the following command:
‘pyinstaller –onefile –runtime-tmpdir=. –hidden-import win32timezone .bot.py’
The error I get:
[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.
I would like to find a solution using pyinstaller, without installing additional utilities. I don’t know what to do anymore.
Thank you for help!
Max Simple is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.