class_docstr: Class for managing value based locking.
docstr: Context manager for input value based locking.
  
  Only one thread can enter the context for a given value.
  
  Args:
    value: Value of any hashable type.
  
  Yields:
    Nothing.
docstr_tok: ["Context","manager","for","input","value","based","locking",".","Only","one","thread","can","enter","the","context","for","a","given","value",".","Args",":","value",":","Value","of","any","hashable","type",".","Yields",":","Nothing","."]
code: def lock(self, value: typing.Hashable) -> Iterator[None]:
      """Context manager for input value based locking.
  
      Only one thread can enter the context for a given value.
  
      Args:
        value: Value of any hashable type.
  
      Yields:
        Nothing.
      """
      with self._main_lock:
          lock = self._locks.setdefault(value, threading.Lock())
          self._refcounts[value] += 1
      try:
          with lock:
              yield
      finally:
          with self._main_lock:
              self._refcounts[value] -= 1
              if self._refcounts[value] <= 0:
                  del self._refcounts[value]
                  del self._locks[value]
  
imports: import collections
  import contextlib
  import copy
  import threading
  import typing
  from typing import Callable, Iterator, MutableMapping, Optional
  import cachetools
  from tfx.orchestration import metadata
  from google.protobuf.internal import containers
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 2 for calling the _LocksManager obj's underlying member method code with example usage: obj.lock(value) without return types