From 0cea56fc3b1689abdc1f5ffe51eb3066c79f3473 Mon Sep 17 00:00:00 2001 From: Simon Kohlmeyer Date: Sat, 25 Mar 2023 02:03:30 +0100 Subject: [PATCH] (Try to) close suprocess file handles after we are done with it This should fix #665 --- invoke/runners.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/invoke/runners.py b/invoke/runners.py index 423cb797..138a3696 100644 --- a/invoke/runners.py +++ b/invoke/runners.py @@ -1385,6 +1385,11 @@ def returncode(self) -> Optional[int]: return self.process.returncode def stop(self) -> None: + for fd in ['stdout', 'stderr', 'stdin']: + try: + getattr(self.process, fd).close() + except: + pass # We tried 🤷 # If we opened a PTY for child communications, make sure to close() it, # otherwise long-running Invoke-using processes exhaust their file # descriptors eventually.