From 0ee757e03a2bf6cf1e22c43139ef36cf96bb6693 Mon Sep 17 00:00:00 2001 From: mpikulski <206748156+ixlmar@users.noreply.github.com> Date: Fri, 13 Feb 2026 11:02:29 +0100 Subject: [PATCH] [TRTLLM-10030][chore] use weakref in atexit handler (#11476) Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com> --- tensorrt_llm/executor/executor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tensorrt_llm/executor/executor.py b/tensorrt_llm/executor/executor.py index 12ffad5cd1..5b45fe520e 100644 --- a/tensorrt_llm/executor/executor.py +++ b/tensorrt_llm/executor/executor.py @@ -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()