From 373138f237ee9100663acea65adecc991fd470c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Br=C3=BCheim?= Date: Fri, 7 Dec 2018 23:04:30 +0100 Subject: [PATCH] Small fixes --- kill.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kill.py b/kill.py index 9b7b41b..b2d57fe 100644 --- a/kill.py +++ b/kill.py @@ -201,6 +201,7 @@ def _get_windows(self): handles = AltTab.list_alttab_windows() except OSError: self.err("Failed to list windows.", traceback.format_exc()) + return self._processes_with_window = {} @@ -309,6 +310,7 @@ def _get_processes_from_ext_call(self): self.err(err) # Parsing process list from output + outstr = None for enc in ["cp437", "cp850", "cp1252", "utf8"]: try: output = output.replace(b"\r\r", b"\r") @@ -317,6 +319,10 @@ def _get_processes_from_ext_call(self): except UnicodeDecodeError: self.dbg(enc, "threw exception") + if not outstr: + self.warn("decoding of output failed") + return + info = {} for line in outstr.splitlines(): if line.strip() == "": @@ -416,6 +422,7 @@ def _is_running_from_ext_call(self, pid): self.err(err) # Parsing process list from output + outstr = None for enc in ["cp437", "cp850", "cp1252", "utf8"]: try: output = output.replace(b"\r\r", b"\r") @@ -424,6 +431,10 @@ def _is_running_from_ext_call(self, pid): except UnicodeDecodeError: self.dbg(enc, "threw exception") + if not outstr: + self.warn("decoding of output failed") + return False + running = "ProcessId={}".format(pid) in outstr.splitlines() self.dbg("(wmic) process with id ", pid, "running" if running else "not running") return running