[MERGED] python/osmo-python-tests[master]: osmoutil: open /dev/null only once

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Fri Feb 24 19:52:14 UTC 2017


Neels Hofmeyr has submitted this change and it was merged.

Change subject: osmoutil: open /dev/null only once
......................................................................


osmoutil: open /dev/null only once

Change-Id: Ic6da34f6c4c5cd3b0786788f4e38c9c6248fca1b
---
M osmopy/osmoutil.py
1 file changed, 6 insertions(+), 1 deletion(-)

Approvals:
  Neels Hofmeyr: Looks good to me, approved; Verified



diff --git a/osmopy/osmoutil.py b/osmopy/osmoutil.py
index 7b20043..01f74cc 100755
--- a/osmopy/osmoutil.py
+++ b/osmopy/osmoutil.py
@@ -23,9 +23,14 @@
 
 """Run a command, with stdout and stderr directed to devnull"""
 
+devnull = None
 
 def popen_devnull(cmd, verbose=True):
-    devnull = open(os.devnull, 'w')
+    global devnull
+    if devnull is None:
+        if verbose:
+            print "Opening /dev/null"
+        devnull = open(os.devnull, 'w')
     if verbose:
         print "Launching: PWD=%s %s" % (os.getcwd(), ' '.join([repr(c) for c in cmd]))
     return subprocess.Popen(cmd, stdout=devnull, stderr=devnull)

-- 
To view, visit https://gerrit.osmocom.org/1909
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic6da34f6c4c5cd3b0786788f4e38c9c6248fca1b
Gerrit-PatchSet: 3
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>


More information about the gerrit-log mailing list