diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py index e13b90d6c0ca..17d66b2e8f64 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -31,10 +31,10 @@ from . import utils from .device_data import DeviceDataManager import re + import time except ImportError as e: raise ImportError (str(e) + "- required module not found") -MAX_SELECT_DELAY = 3600 RJ45_TYPE = "RJ45" @@ -387,26 +387,30 @@ def get_change_event(self, timeout=0): self.sfp_event.initialize() wait_for_ever = (timeout == 0) + # select timeout should be no more than 1000ms to ensure fast shutdown flow + select_timeout = 1000.0 if timeout >= 1000 else float(timeout) port_dict = {} error_dict = {} - if wait_for_ever: - timeout = MAX_SELECT_DELAY - while True: - status = self.sfp_event.check_sfp_status(port_dict, error_dict, timeout) - if bool(port_dict): + begin = time.time() + while True: + status = self.sfp_event.check_sfp_status(port_dict, error_dict, select_timeout) + if bool(port_dict): + break + + if not wait_for_ever: + elapse = time.time() - begin + if elapse * 1000 > timeout: break - else: - status = self.sfp_event.check_sfp_status(port_dict, error_dict, timeout) if status: if port_dict: self.reinit_sfps(port_dict) - result_dict = {'sfp':port_dict} + result_dict = {'sfp': port_dict} if error_dict: result_dict['sfp_error'] = error_dict return True, result_dict else: - return True, {'sfp':{}} + return True, {'sfp': {}} def reinit_sfps(self, port_dict): """