[python-win32] Re: Windows service features and Python

Mark Hammond mhammond at skippinet.com.au
Fri Aug 6 02:16:06 CEST 2004


> > I'm transforming some Python code into a Windows
> > service. I started with pywin32-202.win32-py2.2.exe,
> > and investigated the demo pipeTestService. This
> > worked fine, so I started converting my code, with
> > no paticular Windows system programming experience.

I'm afraid your problems relate to this lack of Windows experience more than
to Python itself.  "Python Programming on Win32" does cover alot of this
stuff in some detail, but general overviews of Windows services would be
useful.

> > Q1) How can I make my Python service support pause/
> >     continue? Implementing SvcPause() and SvcContinue()
> >     seems to be not enough, as I get 'Could not pause
> >     ... service on Local Computer. The service did not
> >     return an error. ...' dialog despite that the
> >     SvcPause() method is executed. After this dialog
> >     I found that the service was stopped, ending within
> >     SvcDoRun(). Please refer to the attached code.

You need to report a status of PAUSED to the service control manager, in the
same way that RUNNING, START_PENDING, STOP_PENDING and STOPPED are alreay
reported.  Indeed, if your pause takes some time, you must periodically
report PAUSE_PENDING, until you actually enter the PAUSED state.

What "pause" means is up to you and your code.  One strategy would be to use
an event, much in the same way that "stop" is handled in the samples.

> > Q2) How can I register my own event IDs/categories? I don't
> >     know where/how to define my own IDs/cats. The demo seems
> >     to support two IDs, servicemanager.PYS_SERVICE_STARTED and
> >     servicemanager.PYS_SERVICE_STOPPED.

See PPWin32 - in a nutshell, there are a number of predefined messages, and
unfortunately you need to look in win32\src\PythonServiceMessages.mc in the
source distribution (or via the CVS viewer).  These .mc files are compiled
using MSVC6 tools, so there is currently no easy to to define your own.  You
are free to use the various "general" ones in PythonServiceMessages.mc.

> > Q3) How can I add counters to the Python service? Looking at
> >     the files perf_install.ini and perf_install.h, this
> >     could be possible, but after install I do not see these
> >     counters in PerfMon. I do not see the way these files
> >     are connected to the service demo source code... Maybe
> >     these are already installed as the readme indicates,
> >     but where should I look?

Sorry, but I can't recall exactly.  perfmon counters are not for the feint
hearted.  Again, PPWin32 covers that.

Mark.



More information about the Python-win32 mailing list