def RestartService(serviceName, args=None, waitSeconds=30, machine=None):
 try:
  StopService(serviceName, machine)
 except pywintypes.error as exc:
  if (exc.winerror != winerror.ERROR_SERVICE_NOT_ACTIVE):
   raise
 for i in range(waitSeconds):
  try:
   StartService(serviceName, args, machine)
   break
  except pywintypes.error as exc:
   if (exc.winerror != winerror.ERROR_SERVICE_ALREADY_RUNNING):
    raise
   win32api.Sleep(1000)
 else:
  print 'Gave up waiting for the old service to stop!'

def RestartService ( serviceName , args = None , waitSeconds = 30 , machine = None ) : try : StopService ( serviceName , machine ) except pywintypes . error as exc : if ( exc . winerror != winerror . ERROR_SERVICE_NOT_ACTIVE ) : raise for i in range ( waitSeconds ) : try : StartService ( serviceName , args , machine ) break except pywintypes . error as exc : if ( exc . winerror != winerror . ERROR_SERVICE_ALREADY_RUNNING ) : raise win32api . Sleep ( 1000 ) else : print 'Gave up waiting for the old service to stop!'
stop the service .