[V1][Core] Use weakref.finalize instead of atexit (#11242)

Signed-off-by: Tyler Michael Smith <tyler@neuralmagic.com>
This commit is contained in:
Tyler Michael Smith
2024-12-16 22:11:33 -08:00
committed by GitHub
parent e88db68cf5
commit 2bfdbf2a36
2 changed files with 5 additions and 18 deletions
+2 -11
View File
@@ -1,5 +1,5 @@
import atexit
import os
import weakref
from typing import List, Optional
import msgspec
@@ -165,15 +165,9 @@ class MPClient(EngineCoreClient):
ready_path=ready_path, # type: ignore[misc]
**kwargs,
)
atexit.register(self.shutdown)
self._finalizer = weakref.finalize(self, self.shutdown)
def shutdown(self):
# During final garbage collection in process shutdown, atexit may be
# None.
if atexit:
# in case shutdown gets called via __del__ first
atexit.unregister(self.shutdown)
# Shut down the zmq context.
self.ctx.destroy(linger=0)
@@ -197,9 +191,6 @@ class MPClient(EngineCoreClient):
os.remove(socket_file)
self.proc_handle = None
def __del__(self):
self.shutdown()
class SyncMPClient(MPClient):
"""Synchronous client for multi-proc EngineCore."""