[python-win32] Windows log out service problem

Mark Hammond mhammond at skippinet.com.au
Wed Aug 8 22:33:14 CEST 2007


I believe this is caused by Windows sending a CTRL_LOGOFF_EVENT to the
service - http://msdn2.microsoft.com/en-us/library/ms683242.aspx has some
details.  Adding your own handler for this notification may allow you to
prevent the problem, but I don't have the time at the moment to experiment
with that.

Cheers,

Mark

> -----Original Message-----
> From: python-win32-bounces at python.org 
> [mailto:python-win32-bounces at python.org] On Behalf Of Zdenek Mejzlik
> Sent: Wednesday, 8 August 2007 2:03 PM
> To: python-win32 at python.org
> Subject: [python-win32] Windows log out service problem
> 
> Hi.
> 
> This post is similar to one sent by Tom Dalton 12 June 2007. 
> Unfortunately, appropriate solution of his problem was not 
> published yet.
> 
> I'm trying to create a simple windows service. I found code 
> of simple service on the Internet. Service works well as long 
> as I'm logged in. 
> But as soon as I log out the service is interrupted and 
> windows event log contains the following message:
> 
> The instance's SvcRun() method failed
> File 
> "C:\Python25\Lib\site-packages\win32\lib\win32serviceutil.py",
>  line 785, in SvcRun
>   self.SvcDoRun()
> File 
> "C:\altworx_repository\wwwroot\cgi-bin\pokus\aservice.py", 
> line 20, in SvcDoRun
>   time.sleep(10)
> <type 'exceptions.IOError'>: (4, 'Interrupted function call')
> 
> Service is running on Windows XP Prof with Python 2.5. Code 
> of the service is bellow. Has anyone any idea what's wrong? 
> Thank you for any little help.
> 
> import win32service
> import win32serviceutil
> import time
> import win32api
> import win32con
> 
> class aservice(win32serviceutil.ServiceFramework):
>  _svc_name_ = "aservice"
>  _svc_display_name_ = "aservice - It Does nothing"
> 
>  def __init__(self,args):
>     win32serviceutil.ServiceFramework.__init__(self,args)
>     self.isAlive = True
> 
>  def SvcDoRun(self):
>     import servicemanager
> 
>     while self.isAlive:
>        servicemanager.LogInfoMsg("aservice - is alive and well")
>        time.sleep(10)
>     servicemanager.LogInfoMsg("aservice - Stopped")
> 
>  def SvcStop(self):
>     import servicemanager
> 
>     servicemanager.LogInfoMsg("aservice - Recieved stop signal")
>     self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
>     self.isAlive = False
> 
> def ctrlHandler(ctrlType):
>  return True
> 
> if __name__ == '__main__':
>  win32api.SetConsoleCtrlHandler(ctrlHandler, True)
>  win32serviceutil.HandleCommandLine(aservice)
> 
> 
> This code is slightly modified. The original code is on 
> http://essiene.blogspot.com/2005/04/python-windows-services.html.
> 
> Z.
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
> 



More information about the python-win32 mailing list