code: def release(self):
          
          #  This decrements the appropriate lock counters, and if the lock
          #  becomes free, it looks for a queued thread to hand it off to.
          #  By doing the handoff here we ensure fairness.
          me = currentThread()
          with self._lock:
              if self.is_exclusive:
                  if self._exclusive_owner is not me:
                      raise RuntimeError("release() called on unheld lock")
                  self.is_exclusive -= 1
                  if not self.is_exclusive:
                      self._exclusive_owner = None
                      #  If there are waiting shared locks, issue it to them
                      #  all and then wake everyone up.
                      if self._shared_queue:
                          for (thread,waiter) in self._shared_queue:
                              self.is_shared += 1
                              self._shared_owners[thread] = 1
                              waiter.notify()
                          del self._shared_queue[:]
                      #  Otherwise, if there are waiting exclusive locks,
                      #  they get first dibbs on the lock.
                      elif self._exclusive_queue:
                          (thread,waiter) = self._exclusive_queue.pop(0)
                          self._exclusive_owner = thread
                          self.is_exclusive += 1
                          waiter.notify()
              elif self.is_shared:
                  try:
                      self._shared_owners[me] -= 1
                      if self._shared_owners[me] == 0:
                          del self._shared_owners[me]
                  except KeyError:
                      raise RuntimeError("release() called on unheld lock")
                  self.is_shared -= 1
                  if not self.is_shared:
                      #  If there are waiting exclusive locks,
                      #  they get first dibbs on the lock.
                      if self._exclusive_queue:
                          (thread,waiter) = self._exclusive_queue.pop(0)
                          self._exclusive_owner = thread
                          self.is_exclusive += 1
                          waiter.notify()
                      else:
                          assert not self._shared_queue
              else:
                  raise RuntimeError("release() called on unheld lock")
docs: Release the lock.