From 3f04e57749689af6d1ea9deda58dbd5fa8562a15 Mon Sep 17 00:00:00 2001 From: toonn Date: Sat, 17 Jul 2021 21:06:42 +0200 Subject: ext.popen_forked: Refactor to use with Because the process forks we can closed the fds on this side. --- ranger/ext/popen_forked.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ranger/ext/popen_forked.py b/ranger/ext/popen_forked.py index bff1818e..85c8448b 100644 --- a/ranger/ext/popen_forked.py +++ b/ranger/ext/popen_forked.py @@ -18,9 +18,12 @@ def Popen_forked(*args, **kwargs): # pylint: disable=invalid-name return False if pid == 0: os.setsid() - kwargs['stdin'] = open(os.devnull, 'r') - kwargs['stdout'] = kwargs['stderr'] = open(os.devnull, 'w') - subprocess.Popen(*args, **kwargs) + with open(os.devnull, 'r') as null_r, open(os.devnull, 'w') as null_w: + kwargs['stdin'] = null_r + kwargs['stdout'] = kwargs['stderr'] = null_w + with subprocess.Popen(*args, **kwargs): + # Just to enable using with + pass os._exit(0) # pylint: disable=protected-access else: os.wait() -- cgit 1.4.1-2-gfad0