O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The servicemanager Module

As mentioned previously in this chapter, PythonService.exe hosts all Python programs running as services. Once this host .exe is running, it makes a module servicemanager available to the Python program. Because your Python scripts are used both by Python.exe (when installing, starting, or debugging the service) and by PythonService.exe (when running as a service), you can’t import this module from the top level of your Python program; the import servicemanager statement will fail for Python.exe. In practice, this means you should only import this module locally to a function.

The primary purpose of servicemanager is to provide facilities for interacting with the SCM at runtime. Most of this interaction is done by the base class win32serviceutil.ServiceFramework(), so in general this is covered for you.

There are, however, some useful utility functions you may wish to use. Among these is a set of functions for writing to the Event Log. The most general purpose is the function LogMsg() , which takes the following parameters:

ErrorType

One of EVENTLOG_INFORMATION_TYPE, EVENTLOG_ERROR_TYPE, or EVENT-LOG_WARNING_TYPE. These constants can be found in servicemanager.

ErrorID

The message ID. This uniquely identifies the message text.

Inserts = None

A list of string inserts for the message or None. The inserts are merged with the message text to provide the final result for the user.

There are three other Event Log-related functions in this module. LogInfoMsg()

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required