]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: remove __del__() of mgr modules 54375/head
authorRamana Raja <rraja@redhat.com>
Thu, 2 Nov 2023 21:44:10 +0000 (17:44 -0400)
committerRamana Raja <rraja@redhat.com>
Mon, 13 Nov 2023 16:07:40 +0000 (11:07 -0500)
It's strongly recommended for objects that have references to
external resources (e.g., files) to explicitly release them.
Python doesn't guarantee garbage collection of objects and hence
doesn't guarantee freeing of external resources that occur on
garbage collection.

The __del__() methods in the python mgr modules may not even be
called since garbage collection of objects is not guaranteed in python.
And some of the __del__() methods try to cleanup that seem redundant.

- In volumes/module.py, vc.shutdown() is called in Module.shutdown().
  No need to call it again in Module.__del__()

- In telegraf/basesocket.py, BaseSocker.close() is called in
  BaseSocket.__exit__(). No need to call it again in
  BaseSocket.__del__().

- In mgr_module.py, MgrModuleLoggingMixin._unconfigure_logging() is
  called in MgrModule.__init__() and MgrStandbyModule.__init__(). No
  need to call it in MgrModule.__del__() and
  MgrStandbyModule.__del__().|

- In dashboard/services/cephfs.py, the libcephfs mount is not
  shutdown explicitly by the mgr module. However, the cython libcephfs
  bindings has a LibCephFS.__dealloc__() finalizer method that calls
  LibCephFS.shutdown(). This should unmount and cleanup the ceph mount
  handle.

Remove the __del__() of the python mgr modules.

Fixes: https://tracker.ceph.com/issues/63421
Signed-off-by: Ramana Raja <rraja@redhat.com>
src/pybind/mgr/dashboard/services/cephfs.py
src/pybind/mgr/mgr_module.py
src/pybind/mgr/telegraf/basesocket.py
src/pybind/mgr/volumes/module.py

index 07b339cc92176382843feb96be2b3d96b78ce632..ffbf9d0c81651b2512334053c33f9abc4231526c 100644 (file)
@@ -45,10 +45,6 @@ class CephFS(object):
             self.cfs.mount()
         logger.debug("mounted cephfs filesystem")
 
-    def __del__(self):
-        logger.debug("shutting down cephfs filesystem")
-        self.cfs.shutdown()
-
     @contextmanager
     def opendir(self, dirpath):
         d = None
index 5a7b9bfc6f6c8671be6cb72252296e5a844d7f9c..6c83f2771619f0991c79286a2b3fab39be8a7861 100644 (file)
@@ -836,13 +836,6 @@ class MgrStandbyModule(ceph_module.BaseMgrStandbyModule, MgrModuleLoggingMixin):
         # for backwards compatibility
         self._logger = self.getLogger()
 
-    def __del__(self) -> None:
-        self._cleanup()
-        self._unconfigure_logging()
-
-    def _cleanup(self) -> None:
-        pass
-
     @classmethod
     def _register_options(cls, module_name: str) -> None:
         cls.MODULE_OPTIONS.append(
@@ -1045,9 +1038,6 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin):
 
         self._db_lock = threading.Lock()
 
-    def __del__(self) -> None:
-        self._unconfigure_logging()
-
     @classmethod
     def _register_options(cls, module_name: str) -> None:
         cls.MODULE_OPTIONS.append(
index 5caea3be72596d8a920474ce7cbff9018cb60f27..463cf326dd05751c22b604c36279e88392c33116 100644 (file)
@@ -38,9 +38,6 @@ class BaseSocket(object):
     def send(self, data: str, flags: int = 0) -> int:
         return self.sock.send(data.encode('utf-8') + b'\n', flags)
 
-    def __del__(self) -> None:
-        self.sock.close()
-
     def __enter__(self) -> 'BaseSocket':
         self.connect()
         return self
index ff7256eebfd34ec16df7ea646f2da69d6584cf11..6227276fcaf576eb28bdb99b8a18424c8d2e68c0 100644 (file)
@@ -506,9 +506,6 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             self.vc = VolumeClient(self)
             self.inited = True
 
-    def __del__(self):
-        self.vc.shutdown()
-
     def shutdown(self):
         self.vc.shutdown()