@@ -0,0 +1,873 @@
+import threading%0A%0A%0Aclass LockingContainer(object):%0A    %22%22%22A context manager that wraps a single value in a threadsafe lock.%22%22%22%0A    def __init__(self, value):%0A        self._lock = threading.RLock()%0A        self._value = value%0A%0A    def replace(self, value):%0A        %22%22%22Replace the contained value.%0A        This is a thread-safe operation.%0A        %22%22%22%0A        with self._lock:%0A            self._value = value%0A%0A    def __enter__(self):%0A        self._lock.acquire()%0A        return self._value%0A%0A    def __exit__(self, exc_type, exc_value, traceback):%0A        self._lock.release()%0A        return False%0A%0A%0Aif __name__ == %22__main__%22:%0A    # Example usage.%0A    menu_locked = LockingContainer(%7B%7D)%0A%0A    with menu_locked as menu:%0A        menu%5B%22eggs%22%5D = %221 dolla%22%0A        print menu%0A%0A    menu_locked.replace(%7B%22nevermind%22: %22we're closed%22%7D)%0A%0A    with menu_locked as menu:%0A        print menu%0A

add lockingcontainer