mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2026-01-08 11:27:29 +08:00
[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>
This commit is contained in:
parent
3e2f7985a2
commit
236b864e4f
@ -1640,15 +1640,19 @@ def weak_bind(bound_method: Callable[..., Any], ) -> Callable[..., None]:
|
||||
return weak_bound
|
||||
|
||||
|
||||
# From: https://stackoverflow.com/a/4104188/2749989
|
||||
def run_once(f: Callable[P, None]) -> Callable[P, None]:
|
||||
|
||||
def wrapper(*args: P.args, **kwargs: P.kwargs) -> None:
|
||||
if not wrapper.has_run: # type: ignore[attr-defined]
|
||||
wrapper.has_run = True # type: ignore[attr-defined]
|
||||
return f(*args, **kwargs)
|
||||
if wrapper.has_run: # type: ignore[attr-defined]
|
||||
return
|
||||
|
||||
with wrapper.lock: # type: ignore[attr-defined]
|
||||
if not wrapper.has_run: # type: ignore[attr-defined]
|
||||
wrapper.has_run = True # type: ignore[attr-defined]
|
||||
return f(*args, **kwargs)
|
||||
|
||||
wrapper.has_run = False # type: ignore[attr-defined]
|
||||
wrapper.lock = threading.Lock() # type: ignore[attr-defined]
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user