code: def is_locked_by_me(self):
          
          
          ## get pid of lock
          lock_pid = self.lock_pid()
  
          ## not locked
          if lock_pid is None:
              logger.debug('Lock {} is not aquired.'.format(self.lock_filename))
              return False
          
          ## locked by me
          if self.pid == lock_pid:
              logger.debug('Lock {} is aquired by me (pid: {}).'.format(self.lock_filename, self.pid))
              return True
  
          ## locked by alive process
          try:
              os.kill(lock_pid, 0)
              logger.debug('Lock {} is aquired by another (alive) process (pid: {}).'.format(self.lock_filename, lock_pid))
          
          ## locked by dead process
          except OSError:
              logger.debug('Lock {} is aquired by a dead process (pid: {}).'.format(self.lock_filename, lock_pid))
              try:
                  lock_fd = os.open(self.lock_filename, os.O_RDWR)
              except FileNotFoundError:
                  logger.debug('The lock is now removed by another process.')
              else:
                  try:
                      fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
                  except BlockingIOError:
                      logger.debug('The lock will be removed by another process.')
                  else:
                      if self.lock_pid() == lock_pid:
                          os.remove(self.lock_filename)
                          fcntl.lockf(lock_fd, fcntl.LOCK_UN)
                          logger.debug('The lock is removed by me.')
                      else:
                          logger.debug('The lock is substituted by another lock.')
                  os.close(lock_fd)
          return False
docs: See if the lock exists and is belongs to this process.