-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
66 additions
and
56 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
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
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,38 @@ | ||
import threading | ||
|
||
class ThreadSafeDict: | ||
def __init__(self): | ||
self._dict = {} | ||
self._lock = threading.Lock() | ||
|
||
def __setitem__(self, key, value): | ||
with self._lock: | ||
self._dict[key] = value | ||
|
||
def __getitem__(self, key): | ||
with self._lock: | ||
return self._dict[key] | ||
|
||
def __delitem__(self, key): | ||
with self._lock: | ||
del self._dict[key] | ||
|
||
def get(self, key, default=None): | ||
with self._lock: | ||
return self._dict.get(key, default) | ||
|
||
def __contains__(self, key): | ||
with self._lock: | ||
return key in self._dict | ||
|
||
def items(self): | ||
with self._lock: | ||
return list(self._dict.items()) | ||
|
||
def keys(self): | ||
with self._lock: | ||
return list(self._dict.keys()) | ||
|
||
def values(self): | ||
with self._lock: | ||
return list(self._dict.values()) |
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