From 682450755f44d6d3e9c4e9bf863a0d687952ca71 Mon Sep 17 00:00:00 2001 From: Olivier Booklage Date: Sat, 16 May 2026 14:57:02 +0200 Subject: [PATCH] Avoid duplicating LD_LIBRARY_PATH entries Skip prepending a directory that is already on LD_LIBRARY_PATH, so a repeated import of run.py does not bloat the variable. Addresses review feedback on #1826. --- run.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/run.py b/run.py index 03a6289..6fa4d85 100644 --- a/run.py +++ b/run.py @@ -52,10 +52,13 @@ if sys.platform.startswith("linux"): _lib_dir = os.path.join(_nvidia_dir, _pkg, "lib") if not os.path.isdir(_lib_dir): continue - # Also expose the directory to child processes - os.environ["LD_LIBRARY_PATH"] = ( - _lib_dir + os.pathsep + os.environ.get("LD_LIBRARY_PATH", "") - ) + # Also expose the directory to child processes, without + # duplicating an entry that is already present. + _ldp = os.environ.get("LD_LIBRARY_PATH", "") + if _lib_dir not in _ldp.split(os.pathsep): + os.environ["LD_LIBRARY_PATH"] = ( + _lib_dir + (os.pathsep + _ldp if _ldp else "") + ) for _so in sorted(glob.glob(os.path.join(_lib_dir, "lib*.so*"))): try: ctypes.CDLL(_so, mode=ctypes.RTLD_GLOBAL)