[python-win32] win32 service not receiving shutdown notification on reboot

Ralf Schmitt ralf at brainbot.com
Fri Dec 2 14:14:06 CET 2005


Ralf Schmitt wrote:
> Hi all,
> 
> I use the attached program to start a win32 service.
> Stopping the service using the service manager works fine, but when I 
> reboot the machine, the service just seems to be killed, without 
> SvcStop/SvcShutdown being called (i.e. it never prints "DONE" on reboot).
> Tested on w2k using python2.3, and on XP using Python 2.4, both using 
> pywin 205.
> 
> Does anybody have an idea?
>

One has to register a console ctrl handler:

import win32api

def handler(*args):
     print "HANDLER:", args
     return True

win32api.SetConsoleCtrlHandler(handler, True)

I'm not sure about the return value of handler, but at least I now get 
my "DONE" in the logfile:

my logfile afterwards contains:
Fri Dec 02 14:00:02 2005 running
Fri Dec 02 14:00:03 2005 running
HANDLER: (5,)
Fri Dec 02 14:00:04 2005 running
Fri Dec 02 14:00:05 2005 running
Fri Dec 02 14:00:06 2005 running
Fri Dec 02 14:00:07 2005 running
Fri Dec 02 14:00:08 2005 running
HANDLER: (5,)
HANDLER: (6,)
HANDLE CTRL:Fri Dec 02 14:00:09 2005 running
5
ACCEPTED: 5
DONE



- Ralf

WTF. Using Windows is just an aburd waste of time.



More information about the Python-win32 mailing list