From d263b53797db492f9d6305e334fa7b9788dc5cc9 Mon Sep 17 00:00:00 2001 From: Harkirat Gill Date: Wed, 18 Sep 2024 09:59:43 -0400 Subject: [PATCH] Fix for GitHub Issue #24: Update Event Stop Behavior amd-smi event is failing to exit as it waits for all threads to complete before exiting. Each thread has to listen for a maximum of 10 seconds prior to exiting in the current implementation. Lowered individual listen time for _event_thread allowing for a quicker exit while still capturing all events (Looped until escape sequence detected). Added logging for escape character, not sure if needed but helps confirm that key press was registered. Change-Id: I916608754798f966980a558342c7c62693252d7f --- amdsmi_cli/amdsmi_commands.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index 086c8bd104..21a7d73753 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -2816,16 +2816,20 @@ class AMDSMICommands(): args.gpu = [args.gpu] print('EVENT LISTENING:\n') - print('Press q and hit ENTER when you want to stop (listening will stop within 10 seconds)') - + print('Press q and hit ENTER when you want to stop.') + self.stop = False threads = [] for device_handle in range(len(args.gpu)): x = threading.Thread(target=self._event_thread, args=(self, device_handle)) threads.append(x) x.start() - while self.stop!= 'q': - self.stop = input("") + while True: + user_input = input() + if user_input == 'q': + print("Escape Sequence Detected; Exiting") + self.stop = True + break for thread in threads: thread.join() @@ -4956,9 +4960,9 @@ class AMDSMICommands(): amdsmi_interface.AmdSmiEvtNotificationType) values_dict = {} - while self.stop!='q': + while not self.stop: try: - events = listener.read(10000) + events = listener.read(2000) for event in events: values_dict["event"] = event["event"] values_dict["message"] = event["message"] @@ -4970,4 +4974,4 @@ class AMDSMICommands(): except Exception as e: print(e) - listener.stop() + listener.stop() \ No newline at end of file