From a69bf7e6a0836c2690d7203119696b842974b5b6 Mon Sep 17 00:00:00 2001 From: PavelMuhortov Date: Thu, 17 Jun 2021 08:59:01 +0300 Subject: [PATCH] add search 'TypeError' error handling --- srchproc.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/srchproc.py b/srchproc.py index 479a8b8..40fc9b2 100644 --- a/srchproc.py +++ b/srchproc.py @@ -76,17 +76,21 @@ class Proc: :return: list of dictionaries with descriptions of found processes """ proc_found = [] - for proc in cls.list(): - if exclude and (exclude in proc['execpid'] or exclude in proc['exename'] or - exclude in proc['exepath'] or exclude in proc['cmdline']): - pass - elif find in proc['execpid'] or find in proc['exename'] or \ - find in proc['exepath'] or find in proc['cmdline']: - proc_found.append(proc) - if len(proc_found) == 0: - return None - else: - return proc_found + try: + for proc in cls.list(): + if exclude and (exclude in proc['execpid'] or exclude in proc['exename'] or + exclude in proc['exepath'] or exclude in proc['cmdline']): + pass + elif find in proc['execpid'] or find in proc['exename'] or \ + find in proc['exepath'] or find in proc['cmdline']: + proc_found.append(proc) + except TypeError as ex: + print('ON', platform, 'PLATFORM', 'search ERROR:', ex) + finally: + if len(proc_found) == 0: + return None + else: + return proc_found if __name__ == "__main__":