[python-win32] Problem with pywin32 and Python 3.8 on Windows Server 2016

Frank.Degerdon at ps.rolls-royce.com Frank.Degerdon at ps.rolls-royce.com
Tue Jan 28 02:07:45 EST 2020


Hello,

i have implemented a windows service in the past with python 2.7 and 3.7. I worked fine with this versions. Now I have to switch the version to 3.8.
And with this environment, I have problems.


Below find the sourcecode for my implementation to install an run the service:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Run application as windows service

Usage : python <script name>.py install
Usage : python <script name>.py start
Usage : python <script name>.py stop
Usage : python <script name>.py remove

Based on demos of Mark Hammond's pywin32 package and the following web sites:
https://code.activestate.com/recipes/576451-how-to-create-a-windows-service-in-python/
http://www.codeproject.com/Articles/1115336/Using-Python-to-Make-a-Windows-Service
"""

import sys
import servicemanager
import win32serviceutil
import win32event

import app
from app import config


class SRMWindchillExportService(win32serviceutil.ServiceFramework):
    _svc_name_ = "PythonServiceTeset3.8"
    _svc_display_name_ = " PythonServiceTeset3.8"
    _svc_description_ = " PythonServiceTeset3.8"


    # Installation of service creates Windows System log event entry:
    #   Source : ServiceControlManager
    #   Event ID: 7045


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

    def SvcStop(self):
        win32event.SetEvent(self.hWaitStop)
        # Create Event Log entry:
        #    Level:    Information
        #    Source:   self._svc_name_
        #    Event ID: 4100
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STOPPED,
                              (self._svc_name_, ''))

    def SvcDoRun(self):
        # Create Event Log entry:
        #    Level:    Information
        #    Source:   self._svc_name_
        #    Event ID: 4098
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              (self._svc_name_, ''))

        self.timeout = config.ServiceTimeout  # time value in milliseconds

        msg = "Service: {0}\n" \
              "------------------------------------------------------\n" \
              "Repeating time: every {1} milliseconds.\n".format(self._svc_name_, self.timeout)
        servicemanager.LogInfoMsg(msg)

        application = app.Application()

        while 1:
            # Do the job.
            # If an exception occurs in app.run, the service would crash.
            # Therefore we have to catch all exceptions to ensure the
            # service keeps running.
            # In case of an exception write an error message to event log.
            try:
                application.run()
            except:
                # In case of any exception, report an error to event log,
                # but do not stopp the service!
                # Info is reported with "Source: _svc_name_" and Event ID: 255
                servicemanager.LogErrorMsg("ERROR in {0}: {1}".format(self._svc_name_, sys.exc_info()))


            # Wait for service stop signal, if I timeout, loop again
            rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
            # Check to see if self.hWaitStop happened
            if rc == win32event.WAIT_OBJECT_0:
                # Stop signal encountered. Break the loop.
                break
            else:
                # Loop again
                pass


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


The problem occurs at the start of the service and shows the following errormessage:
[cid:image001.png at 01D5D5B1.D202E370]

In the eventviewer are 3 events with error:
[cid:image002.png at 01D5D5B1.D202E370]


For this error, I found a case at Microsoft:
https://answers.microsoft.com/en-us/windows/forum/windows_10-security/event-id-10016-runtime-broker/18c291c6-f2a1-4f3c-b4ad-2b7ff59fd9f9?page=3

But this didn't help to solve the issue. Anyone have had this problem before?

Thanks.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20200128/60ffc835/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 6146 bytes
Desc: image001.png
URL: <http://mail.python.org/pipermail/python-win32/attachments/20200128/60ffc835/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 22679 bytes
Desc: image002.png
URL: <http://mail.python.org/pipermail/python-win32/attachments/20200128/60ffc835/attachment-0003.png>


More information about the python-win32 mailing list