diff options
author | toonn <toonn@toonn.io> | 2021-07-17 21:06:42 +0200 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2021-07-20 23:17:45 +0200 |
commit | 3f04e57749689af6d1ea9deda58dbd5fa8562a15 (patch) | |
tree | 0289703efdd62548038d3facbf0612f6c8752bce | |
parent | 114a492d9c93aa300c6c64e2d20476698178a045 (diff) | |
download | ranger-3f04e57749689af6d1ea9deda58dbd5fa8562a15.tar.gz |
ext.popen_forked: Refactor to use with
Because the process forks we can closed the fds on this side.
-rw-r--r-- | ranger/ext/popen_forked.py | 9 |
1 files 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() |