Fix issue: exception occurred during chassis object being destroyed (#7446)
The following error message is observed during chassis object being destroyed "Exception ignored in: <function Chassis.__del__ at 0x7fd22165cd08> Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sonic_platform/chassis.py", line 83, in __del__ ImportError: sys.meta_path is None, Python is likely shutting down The chassis tries to import deinitialize_sdk_handle during being destroyed for the purpose of releasing the sdk_handle. However, importing another module during shutting down can cause the error because some of the fundamental infrastructures are no longer available." This error occurs when a chassis object is created and then destroyed in the Python shell. - How I did it To fix it, record the deinitialize_sdk_handle in the chassis object when sdk_handle is being initialized and call the deinitialize handler when the chassis object is being destroyed - How to verify it Manually test.
This commit is contained in:
parent
e3b2a040b2
commit
b3a283366c
@ -73,6 +73,7 @@ class Chassis(ChassisBase):
|
||||
self.sfp_event_initialized = False
|
||||
self.reboot_cause_initialized = False
|
||||
self.sdk_handle = None
|
||||
self.deinitialize_sdk_handle = None
|
||||
logger.log_info("Chassis loaded successfully")
|
||||
|
||||
|
||||
@ -80,9 +81,8 @@ class Chassis(ChassisBase):
|
||||
if self.sfp_event_initialized:
|
||||
self.sfp_event.deinitialize()
|
||||
|
||||
if self.sdk_handle:
|
||||
from sonic_platform.sfp import deinitialize_sdk_handle
|
||||
deinitialize_sdk_handle(self.sdk_handle)
|
||||
if self.deinitialize_sdk_handle:
|
||||
self.deinitialize_sdk_handle(self.sdk_handle)
|
||||
|
||||
|
||||
def initialize_psu(self):
|
||||
@ -140,10 +140,12 @@ class Chassis(ChassisBase):
|
||||
|
||||
def get_sdk_handle(self):
|
||||
if not self.sdk_handle:
|
||||
from sonic_platform.sfp import initialize_sdk_handle
|
||||
from sonic_platform.sfp import initialize_sdk_handle, deinitialize_sdk_handle
|
||||
self.sdk_handle = initialize_sdk_handle()
|
||||
if self.sdk_handle is None:
|
||||
logger.log_error('Failed to open SDK handle')
|
||||
else:
|
||||
self.deinitialize_sdk_handle = deinitialize_sdk_handle
|
||||
return self.sdk_handle
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user