A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[BugFix] Make `run_once` thread-safe (#22978)
Signed-off-by: <wenji.yyc@alibaba-inc.com> Signed-off-by: Yichen Yan <wenji.yyc@alibaba-inc.com>
Yichen Yan committed
Aug 16, 2025 at 07:56 UTC
236b864e4f74c4018e1111e0d5b787d54b37c694
1 file changed
+8
-4
vllm/utils/__init__.py
+8
-4
@@ -1640,15 +1640,19 @@ def weak_bind(bound_method: Callable[..., Any], ) -> Callable[..., None]:
1640
return weak_bound
1641
1642
1643
-# From: https://stackoverflow.com/a/4104188/2749989
1643
def run_once(f: Callable[P, None]) -> Callable[P, None]:
1644
1645
def wrapper(*args: P.args, **kwargs: P.kwargs) -> None:
1647
- if not wrapper.has_run: # type: ignore[attr-defined]
1648
- wrapper.has_run = True # type: ignore[attr-defined]
1649
- return f(*args, **kwargs)
1646
+ if wrapper.has_run: # type: ignore[attr-defined]
1647
+ return
1648
+
1649
+ with wrapper.lock: # type: ignore[attr-defined]
1650
+ if not wrapper.has_run: # type: ignore[attr-defined]
1651
+ wrapper.has_run = True # type: ignore[attr-defined]
1652
+ return f(*args, **kwargs)
1653
1654
wrapper.has_run = False # type: ignore[attr-defined]
1655
+ wrapper.lock = threading.Lock() # type: ignore[attr-defined]
1656
return wrapper
1657
1658