[python-win32] HTTP Server as a Windows Service

Paul Moore p.f.moore at gmail.com
Mon Feb 25 13:42:27 CET 2008


On 22/02/2008, Larry Bates <larry.bates at websafe.com> wrote:
>  This seems to come up about every other week.  The problem is that you haven't
>  given your service a way to KNOW that you have sent a stop signal.  Below is a
>  skeleton of a correct SvcDoRun method:

In fact, the code shown uses self.isAlive for this purpose. An event
would probably be better than a single flag variable, as the different
methods of a service program tend to get called from different threads
in the service control program, so something thread-safe is advisable.
It shouldn't matter in this case, though.

The real problem here is that the OP hasn't notified the service
control manager that it has stopped, once SvcDoRun completes. He needs
a call to self.ReportServiceStatus(win32service.SERVICE_STOPPED)
outside the while loop in SvcDoRun. Otherwise the status never gets
set to "Stop", and remains at "Stopping" as he is seeing.

>  You may want to invest in a book: "Python Programming On Win32" it helped me a
>  lot when I was getting started.

Absolutely. That's a great book, and well worth a read for service
programming in particular.

>  Note: I don't think you want to define your RequestHandler class inside SvcDoRun
>  and instantiate the HTTPserver every time through the loop.  You should just
>  update the information on the page each time through the loop.

Again, I'd agree, but the given code looks OK for a quick hack.

Paul.


More information about the python-win32 mailing list