Skip to content

Commit

Permalink
Fix issue: exception occurred during chassis object being destroyed (s…
Browse files Browse the repository at this point in the history
…onic-net#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.
  • Loading branch information
stephenxs authored and Carl Keene committed Aug 7, 2021
1 parent dadcc37 commit 57f91b0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ def __init__(self):
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")


def __del__(self):
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):
Expand Down Expand Up @@ -140,10 +140,12 @@ def initialize_sfp(self):

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


Expand Down

0 comments on commit 57f91b0

Please sign in to comment.