Created
December 18, 2023 10:11
-
-
Save victory-sokolov/0d4157acea5ff4ed775ff0ca24519c36 to your computer and use it in GitHub Desktop.
Python lock context manager
This file contains hidden or 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
from multiprocessing import Manager | |
class ContextLock: | |
def __init__(self) -> None: | |
self.manager = Manager() | |
self.lock = self.manager.Lock() | |
def __enter__(self) -> bool: | |
return self.lock.aacquire() | |
def __exit__(self, _type, _value, _traceback) -> None: | |
self.lock.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment