Installing, Debugging, and Running a Python Service

Now that we have a service written in Python, what to do with it? This section discusses installing the service, debugging the service, and starting and stopping the service.

Installing the service

As discussed previously, an application named PythonService.exe hosts all Python services. This executable must be registered before you can install the service. The registration process need only be run once per machine, regardless of how many services the program hosts. The installation package for the Python for Windows extensions automatically registers this, but the information is included here for completeness. To register PythonService.exe, perform the following steps:

  1. Start a command prompt.

  2. Change to the directory containing PythonService.exe, typically \Program Files \Python\win32.

  3. Execute the command:

    C:\Program Files\Python\win32>PythonService.exe /register
    Registering the Python Service Manager...
    C:\Program Files\Python\win32>

Now to install the service, perform the following steps:

  1. Start a command prompt.

  2. Change to the directory containing the Python source code that implements the service.

  3. Execute the command:

    C:\Scripts> SmallestService.py install
    Installing service SmallestPythonService to Python class 
       C:\Scripts\SmallestService.SmallestPythonService
    Service installed
    C:\Scripts>

The service is now installed and ready to run. To confirm the service has been correctly installed, use the control panel to start the Services applet ...

Get Python Programming On Win32 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.