From fc66248586b4d3355225781cfa071c0f18745954 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 22 Jan 2024 15:16:31 +0200 Subject: [PATCH] Fix the Subprocess finalizer --- tests/subprocess.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/subprocess.py b/tests/subprocess.py index 8757605..ea03d67 100644 --- a/tests/subprocess.py +++ b/tests/subprocess.py @@ -191,8 +191,13 @@ def alive(self) -> bool: return self._inferior.poll() is None def __del__(self) -> None: - if self._inferior.poll() is None: - self._inferior.kill() + try: + inf = self._inferior + except AttributeError: + pass # Ignore semi-constructed objects. + else: + if inf.poll() is None: + inf.kill() def _read_stream(io: typing.Any) -> str: