[TRTLLM-10030][chore] use weakref in atexit handler (#11476)

Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
This commit is contained in:
mpikulski 2026-02-13 11:02:29 +01:00 committed by GitHub
parent ca499d600d
commit 0ee757e03a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ import multiprocessing
import platform
import signal
import traceback
import weakref
from abc import ABC, abstractmethod
from collections.abc import Mapping
from pathlib import Path
@ -88,7 +89,10 @@ class GenerationExecutor(ABC):
self.kv_events_queues = IterationResultQueue()
self.stats_queues = IterationResultQueue()
atexit.register(self.shutdown)
atexit.register(
lambda ref, finalizer=type(self).shutdown: finalizer(obj)
if (obj := ref()) is not None else None,
weakref.ref(self))
# This is used to capture the exceptions from the threads.
self._error_queue = Queue()