From 8d5ced1f60403e6e90d4e28d17294b82c8b559d2 Mon Sep 17 00:00:00 2001 From: Ori Messinger Date: Fri, 9 Jul 2021 00:41:30 -0400 Subject: [PATCH] ROCm SMI Python CLI: Fix printLog Collisions Python's default 'print' implementation is not thread safe, causing empty lines to be printed during multithreaded code execution. This fixes the --showevents output for multi-GPU systems. Signed-off-by: Ori Messinger Change-Id: I72f7341cdf4401f1fed4cd8f7d7a4a90bf9a3a4c --- python_smi_tools/rocm_smi.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python_smi_tools/rocm_smi.py b/python_smi_tools/rocm_smi.py index 43309ef639..f1fedf3e7f 100755 --- a/python_smi_tools/rocm_smi.py +++ b/python_smi_tools/rocm_smi.py @@ -440,7 +440,6 @@ def printEventList(device, delay, eventList): @param delay: Notification delay in ms @param eventList: List of event type names (can be a single-item list) """ - print2DArray([['DEVICE\t', 'TIME\t', 'TYPE\t', 'DESCRIPTION']]) mask = 0 ret = rocmsmi.rsmi_event_notification_init(device) if not rsmi_ret_ok(ret, device): @@ -483,7 +482,8 @@ def printLog(device, metricName, value): if device is None: logstr = logstr[13:] logging.debug(logstr) - print(logstr) + # Force thread safe printing + print(logstr + '\n\r', end='') def printListLog(metricName, valuesList): @@ -2129,7 +2129,9 @@ def showEvents(deviceList, eventTypes): printErrLog(None, 'Ignoring unrecognized event type %s' % (event.replace(',', ''))) if len(eventTypeList) == 0: eventTypeList = notification_type_names - try: # Create a seperate thread for each GPU + try: + print2DArray([['DEVICE\t', 'TIME\t', 'TYPE\t', 'DESCRIPTION']]) + # Create a seperate thread for each GPU for device in deviceList: _thread.start_new_thread(printEventList, (device, 1000, eventTypeList)) time.sleep(0.25)