forked from chroma-core/chroma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Thread-safety for persistent and ephemeral clients
Refs: chroma-core#1209, chroma-core#1234
- Loading branch information
Showing
3 changed files
with
75 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import threading | ||
from functools import wraps | ||
from typing import Callable | ||
|
||
lock = threading.RLock() | ||
|
||
|
||
def synchronized(function: Callable) -> Callable: | ||
""" | ||
Decorator to synchronize a function call on a global lock. This allows us to | ||
ensure thread safety while allowing multiple persistent or ephemeral clients to | ||
be created. | ||
""" | ||
@wraps(function) | ||
def wrapped(*args, **kwargs): | ||
with lock: | ||
return function(*args, **kwargs) | ||
return wrapped |