rocm_smi.py: Fix pipe into head error
When piping rocm_smi into 'head' it failed with "Broken pipe" error. The
error can be safely ignored. head closes the pipe early which causes
calls a SIGPIPE signal to be raised.
https://docs.python.org/3/library/signal.html#note-on-sigpipe
Change-Id: I4a589c6ed9a8c5b50de84b33e28115c6b510045f
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
[ROCm/amdsmi commit: 094c98a74f]
This commit is contained in:
committed by
Dmitrii Galantsev
parent
cabd0528b9
commit
5b362b65ce
@@ -638,10 +638,21 @@ def printLog(device, metricName, value=None, extraSpace=False, useItalics=False)
|
|||||||
lock.acquire()
|
lock.acquire()
|
||||||
if useItalics:
|
if useItalics:
|
||||||
logstr = italics + logstr + end
|
logstr = italics + logstr + end
|
||||||
if extraSpace:
|
try:
|
||||||
print('\n' + logstr + '\n', end='', flush=True)
|
if extraSpace:
|
||||||
else:
|
print('\n', end='')
|
||||||
print(logstr + '\n', end='', flush=True)
|
print(logstr + '\n', end='')
|
||||||
|
sys.stdout.flush()
|
||||||
|
# when piped into programs like 'head' - print throws an error.
|
||||||
|
# silently ignore instead
|
||||||
|
except(BrokenPipeError, IOError):
|
||||||
|
# https://docs.python.org/3/library/signal.html#note-on-sigpipe
|
||||||
|
# Python flushes standard streams on exit; redirect remaining output
|
||||||
|
# to devnull to avoid another BrokenPipeError at shutdown
|
||||||
|
devnull = os.open(os.devnull, os.O_WRONLY)
|
||||||
|
os.dup2(devnull, sys.stdout.fileno())
|
||||||
|
sys.exit(1) # Python exits with error code 1 on EPIPE
|
||||||
|
|
||||||
lock.release()
|
lock.release()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user