[python-win32] Problem with service start type "auto"

Mark Hammond skippy.hammond at gmail.com
Thu May 20 00:28:35 CEST 2010


I'd suggest that remove almost all code from your __init__ function, and 
instead put it all in SvcDoRun - once SvcDoRun has been called we have 
already reported success to the service control manager and taking a 
little time to, eg, enumerate the registry will not cause problems.

HTH,

Mark

On 19/05/2010 11:36 PM, Boris Perez Canedo wrote:
> Hi everybody.
>
> I'm new in the list and I'm not an english speaking person. If you see a
> lot of mistakes please excuse me I'm trying my best.
>
> I have a compiled python service which I can install, remove, start and
> stop without errors (manually). The problem ocurrs when I change the
> start type and set it to "auto". Then I restart my computer to see if
> the service starts correctly. I see two errors informed by the service
> control manager:
>
> 1)Timeout (30000 ms.) for connection to WBEM Inv service.
>
> And right after that.
>
> 2)The service did not responde to the start or control request in a
> timely fashion.
>
> If I go and perform an explicit start, keeping the start type in auto,
> the service starts and no errors are informed.
>
> I don't understand why the operating system can not start the service by
> itself.
>
> This is the output for "sc interrogate" on my service in case it helps:
>
> SERVICE_NAME: WBEMInv
> TYPE : 10 WIN32_OWN_PROCESS
> STATE : 4 RUNNING
> (STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
> WIN32_EXIT_CODE : 0 (0x0)
> SERVICE_EXIT_CODE : 0 (0x0)
> CHECKPOINT : 0x0
> WAIT_HINT : 0x0
>
>
> My python code:
>
> import win32serviceutil
> import win32service
> import win32event
> import servicemanager
> import os
>
> def system():
> # my system implementation.
>
> class XmlRPCService(win32serviceutil.ServiceFramework):
> _svc_name_ = 'WBEMInv'
> _svc_display_name_ = "WBEM Inventory"
> _svc_description_ = 'Servicio xml rpc para realizar inventario de
> ordenadores conectados a redes hibridas'
> def __init__(self, args):
> key =
> _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\\UCf\\WBEMInv\\Settings")
> path = _winreg.EnumValue(key, 0)[1]
> os.chdir(path) # I dont want the working directory to be system32.
> _winreg.CloseKey(key)
> win32serviceutil.ServiceFramework.__init__(self, args)
> self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
> def SvcStop(self):
> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
> sys.stopservice = "true"
> win32event.SetEvent(self.hWaitStop)
> def SvcDoRun(self):
> system()
>
> if __name__=='__main__':
> win32serviceutil.HandleCommandLine(XmlRPCService)
>
> Thank you very much.
>
> Boris.
>
> ------------------------------------------------------------------------
>
> Convencion Internacional de Psicologia y Ciencias Sociales y Humanas
>
> Cienfuegos, Cuba, del 19 al 22 de abril del 2011
>
> http://promociondeeventos.sld.cu/hominis2011
>
>
>
> _______________________________________________
> 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