Return and generate if required the lock for this request.
544275
def lock(self) -> asyncio.Lock:
        

        if self.lock_key not in self.request.custom_content:
            self.request.custom_content[self.lock_key] = asyncio.Lock()

        return self.request.custom_content[self.lock_key]
1360896
def is_already_locked(request, get_username=get_username_from_request, username=None):
    """"""
    user_blocked = is_user_already_locked(username or get_username(request))
    ip_blocked = is_source_ip_already_locked(get_ip(request))

    if config.LOCKOUT_BY_IP_USERNAME:
        # if both this IP and this username are present the request is blocked
        return ip_blocked and user_blocked

    return ip_blocked or user_blocked
1035186
def _create_lock_object(self, key):
        '''
        
        '''
        return redis_lock.Lock(self.redis_conn, key,
                               expire=self.settings['REDIS_LOCK_EXPIRATION'],
                               auto_renewal=True)
673336
def run(self):
        
        while True:
            self.open_lock.acquire()
            if self.stopped():
                return
            self.__open()
            self.open_lock.release()
114144
def lock(timeout = nil, &block)
      Scripts.call(:lock, redis_pool,
                   keys: [exists_key, grabbed_key, available_key, UNIQUE_SET, unique_digest],
                   argv: [jid, ttl, lock_type])

      grab_token(timeout) do |token|
        touch_grabbed_token(token)
        return_token_or_block_value(token, &block)
      end
    end
1363919
async def is_locked(self, resource):
        

        with await self.connect() as redis:
            lock_identifier = await redis.get(resource)
        if lock_identifier:
            return True
        else:
            return False
877544
def gen_lock(self, lock_type='update', timeout=0, poll_interval=0.5):
        '''
        
        '''
        if not isinstance(lock_type, six.string_types):
            raise GitLockError(
                errno.EINVAL,
                'Invalid lock_type \'{0}\''.format(lock_type)
            )

        # Make sure that we have a positive integer timeout, otherwise just set
        # it to zero.
        try:
            timeout = int(timeout)
        except ValueError:
            timeout = 0
        else:
            if timeout < 0:
                timeout = 0

        if not isinstance(poll_interval, (six.integer_types, float)) \
                or poll_interval < 0:
            poll_interval = 0.5

        if poll_interval > timeout:
            poll_interval = timeout

        lock_set = False
        try:
            time_start = time.time()
            while True:
                try:
                    self._lock(lock_type=lock_type, failhard=True)
                    lock_set = True
                    yield
                    # Break out of his loop once we've yielded the lock, to
                    # avoid continued attempts to iterate and establish lock
                    break
                except (OSError, IOError, GitLockError) as exc:
                    if not timeout or time.time() - time_start > timeout:
                        raise GitLockError(exc.errno, exc.strerror)
                    else:
                        log.debug(
                            'A %s lock is already present for %s remote '
                            '\'%s\', sleeping %f second(s)',
                            lock_type, self.role, self.id, poll_interval
                        )
                        time.sleep(poll_interval)
                        continue
        finally:
            if lock_set:
                self.clear_lock(lock_type=lock_type)
959433
def _get_template_pool_lock(self, id):
        """"""
        try:
            return self._hosting_device_locks[id]
        except KeyError:
            self._hosting_device_locks[id] = threading.Lock()
            return self._hosting_device_locks.get(id)
239969
def acquire_lock(path: str, blocking: bool) -> Generator[Optional[int], None, None]:
    """"""
    try:
        with open(path, "w+") as lockfile:
            if not blocking:
                lock_command = fcntl.LOCK_EX | fcntl.LOCK_NB
            else:
                lock_command = fcntl.LOCK_EX

            fcntl.lockf(lockfile.fileno(), lock_command)
            yield lockfile.fileno()
            fcntl.lockf(lockfile.fileno(), fcntl.LOCK_UN)

    except FileNotFoundError:
        yield
1024677
def lock(self, id=str(uuid.uuid4()), ttl=DEFAULT_TIMEOUT):
        
        return Lock(id, ttl=ttl, client=self)
699618
def _needs_document_lock(func):
    '''
    '''
    @gen.coroutine
    def _needs_document_lock_wrapper(self, *args, **kwargs):
        # while we wait for and hold the lock, prevent the session
        # from being discarded. This avoids potential weirdness
        # with the session vanishing in the middle of some async
        # task.
        if self.destroyed:
            log.debug("Ignoring locked callback on already-destroyed session.")
            raise gen.Return(None)
        self.block_expiration()
        try:
            with (yield self._lock.acquire()):
                if self._pending_writes is not None:
                    raise RuntimeError("internal class invariant violated: _pending_writes " + \
                                       "should be None if lock is not held")
                self._pending_writes = []
                try:
                    result = yield yield_for_all_futures(func(self, *args, **kwargs))
                finally:
                    # we want to be very sure we reset this or we'll
                    # keep hitting the RuntimeError above as soon as
                    # any callback goes wrong
                    pending_writes = self._pending_writes
                    self._pending_writes = None
                for p in pending_writes:
                    yield p
            raise gen.Return(result)
        finally:
            self.unblock_expiration()
    return _needs_document_lock_wrapper
809709
def trylock(self):
        ""
        if self.locked:
            return True
        if self.lockroutine:
            return False
        waiter = self.scheduler.send(LockEvent(self.context, self.key, self))
        if waiter:
            return False
        else:
            self.locked = True
            return True
1101037
private function doAcquire(): \Generator {
        // Try to create the lock file. If the file already exists, someone else
        // has the lock, so set an asynchronous timer and try again.
        while (($handle = @\fopen($this->fileName, 'x')) === false) {
            yield new Delayed(self::LATENCY_TIMEOUT);
        }

        // Return a lock object that can be used to release the lock on the mutex.
        $lock = new Lock(0, function () {
            $this->release();
        });

        \fclose($handle);

        return $lock;
    }
572789
def try_lock
      locked = false
      Thread.exclusive do
        clean
        unless(locked?(false))
          do_lock
          locked = true
        else
          locked = owner?(Thread.current)
        end
      end
      locked
    end
661231
def lock(self, session):
        
        if self.busy:
            raise ConnectionBusyError(self)
        with self._lock:
            self.used_by = weakref.ref(session)
        LOGGER.debug('Connection %s locked', self.id)
411781
private boolean isLocked(Class entityType, String entityKey) throws LockingException {
        return isLocked(entityType, entityKey, null);
    }
25322
def is_locked(self, key):
        
        key = str(key)
        if key in self.__variable_locks:
            return self.__variable_locks[key].locked()
        return False