osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

exception should not stop program.


On 2017-10-07 17:38, Prabu T.S. wrote:
> I would like to continue to second function invocation "checkServiceStatus('AdobeARMservice')" even if the first
>     checkServiceStatus('Tomcat9')  has any exception.Please advice.Second function invocation not getting executed if any exception occurs in first.Please advice.
> 
> 
> import psutil
> 
> def checkServiceStatus(server):
>      status = None
>      try:
>          service = psutil.win_service_get(server)
>          status = service.as_dict()
>          print("%s (%s)" % (status['name'], status['display_name']))
>          print("status: %s, start: %s, username: %s, pid: %s" % (
>          status['status'], status['start_type'], status['username'], status['pid']))
>          print("binpath: %s" % status['binpath'])
>          print(" ")
>      except Exception:
>          pass
>      return status
> 
> checkServiceStatus('Tomcat9')
> checkServiceStatus('AdobeARMservice')
> 
Catch the exception that's raised, like you're already doing in 
checkServiceStatus.