about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2021-07-17 21:11:30 +0200
committertoonn <toonn@toonn.io>2021-07-20 23:17:45 +0200
commit2f6e7c151d9e537cf6d7e857582418b70d4b34ba (patch)
tree375e1dd6c5e9d924ae4b0d374b8dee44658b8b9d
parent3f04e57749689af6d1ea9deda58dbd5fa8562a15 (diff)
downloadranger-2f6e7c151d9e537cf6d7e857582418b70d4b34ba.tar.gz
ext.spawn: Refactor to use with
-rw-r--r--ranger/ext/spawn.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/ranger/ext/spawn.py b/ranger/ext/spawn.py
index dacb3c4a..d4590c48 100644
--- a/ranger/ext/spawn.py
+++ b/ranger/ext/spawn.py
@@ -28,12 +28,12 @@ def check_output(popenargs, **kwargs):
     kwargs.setdefault('shell', isinstance(popenargs, str))
 
     if 'stderr' in kwargs:
-        process = Popen(popenargs, **kwargs)
-        stdout, _ = process.communicate()
+        with Popen(popenargs, **kwargs) as process:
+            stdout, _ = process.communicate()
     else:
         with open(devnull, mode='w') as fd_devnull:
-            process = Popen(popenargs, stderr=fd_devnull, **kwargs)
-            stdout, _ = process.communicate()
+            with Popen(popenargs, stderr=fd_devnull, **kwargs) as process:
+                stdout, _ = process.communicate()
 
     if process.returncode != 0:
         error = CalledProcessError(process.returncode, popenargs)