osmoutil: open /dev/null only once

Change-Id: Ic6da34f6c4c5cd3b0786788f4e38c9c6248fca1b
This commit is contained in:
Neels Hofmeyr 2017-02-24 20:49:51 +01:00
parent b59b677c9b
commit f6ab3d8e9c
1 changed files with 6 additions and 1 deletions

View File

@ -23,9 +23,14 @@ import time
"""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)