From e62dfabc829cd3302da2e0cbc4efdb68a5413ca2 Mon Sep 17 00:00:00 2001 From: Benedek Racz Date: Fri, 24 Jan 2020 16:24:03 +0100 Subject: [PATCH] [FIX] process termination: do not terminate a process, which has not been started. --- wexpect/spawn.py | 13 +++++++++---- wexpect/wexpect_util.py | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/wexpect/spawn.py b/wexpect/spawn.py index 1376cd0..33ed162 100644 --- a/wexpect/spawn.py +++ b/wexpect/spawn.py @@ -292,10 +292,11 @@ class SpawnBase: try: logger.info('Deleting...') - self.terminate() - self.disconnect_from_child() - if self.safe_exit: - self.wait() + if self.child_process is not None: + self.terminate() + self.disconnect_from_child() + if self.safe_exit: + self.wait() except: traceback.print_exc() logger.warning(traceback.format_exc()) @@ -425,6 +426,10 @@ class SpawnBase: def isalive(self, console=True): """True if the child is still alive, false otherwise""" + if self.child_process is None: + # Child process has not been started... Not alive + return False + try: self.exitstatus = self.child_process.wait(timeout=0) except psutil.TimeoutExpired: diff --git a/wexpect/wexpect_util.py b/wexpect/wexpect_util.py index 509ba90..cbedbbc 100644 --- a/wexpect/wexpect_util.py +++ b/wexpect/wexpect_util.py @@ -162,7 +162,7 @@ class ExceptionPexpect(Exception): def __filter_not_wexpect(self, trace_list_item): """This returns True if list item 0 the string 'wexpect.py' in it. """ - if trace_list_item[0].find('wexpect.py') == -1: + if trace_list_item[0].find('spawn.py') == -1: return True else: return False