[python-win32] win32 service not receiving shutdown notification on reboot
Ralf Schmitt
ralf at brainbot.com
Thu Dec 1 20:13:24 CET 2005
Tim Roberts schrieb:
>On Wed, 30 Nov 2005 17:41:32 +0100, Ralf Schmitt <ralf at brainbot.com>
>
>
>
>>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?
>>
>>
>>
>>
>
>Umm, do you realize that your 'print "DONE"' statement is not part of
>the SvcStop function, but rather the SvcDoRun function?
>
>
>
Yes, but if SvcStop is called, SvcDoRun should also finish
afterwards...one can see the "DONE"
being printed when stopping the service with the service manager, but
not when rebooting the machine.
Adding a print statement in in SvcStop (as the first thing it does),
also doesn't get me any output...
To me it looks like it really just is not being called.
- Ralf
>>#! /usr/bin/env python
>>
>>import sys
>>import time
>>import win32serviceutil, win32service
>>
>>class MyTwistedService(win32serviceutil.ServiceFramework):
>> _svc_name_ = 'AA'
>> _svc_display_name_ = 'AA'
>> def SvcDoRun(self):
>> # Can't use stdout for logging -- .flush will barf
>> sys.stdout = open('c:/mylog.txt','a', 0)
>> self.shouldStop = False
>> while not self.shouldStop:
>> print time.ctime(), "running"
>> time.sleep(1)
>>
>> print "DONE"
>>
>> def SvcStop(self):
>> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
>> self.shouldStop = True
>>
>>
>> SvcShutdown = SvcStop
>>
>>if __name__ == '__main__':
>> win32serviceutil.HandleCommandLine(MyTwistedService)
>>
>>
>>
>>
>
>
>
>
More information about the Python-win32
mailing list