當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.LockError方法代碼示例

本文整理匯總了Python中redis.exceptions.LockError方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.LockError方法的具體用法?Python exceptions.LockError怎麽用?Python exceptions.LockError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.exceptions的用法示例。


在下文中一共展示了exceptions.LockError方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_sync_parallel

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def test_sync_parallel(alter_xmlrpc):
    alter_xmlrpc([dict(name='packageD', summary='Test package.', version='3.0.0'), ])
    redis.delete(POLL_SIMPLE_THROTTLE)

    redis_key = CELERY_LOCK.format(task_name='pypi_portal.tasks.pypi.update_package_list')
    lock = redis.lock(redis_key, timeout=1)
    assert lock.acquire(blocking=False)

    assert '302 FOUND' == current_app.test_client().get('/pypi/sync').status

    expected = [('packageB', 'Test package.', '3.0.0'), ]
    actual = db.session.query(Package.name, Package.summary, Package.latest_version).all()
    assert expected == actual

    try:
        lock.release()
    except LockError:
        pass 
開發者ID:Robpol86,項目名稱:Flask-Large-Application-Example,代碼行數:20,代碼來源:test_pypi_packages.py

示例2: deploy_create2_safe_task

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def deploy_create2_safe_task(self, safe_address: str, retry: bool = True) -> None:
    """
    Check if user has sent enough ether or tokens to the safe account
    If every condition is met safe is deployed
    :param safe_address: safe account
    :param retry: if True, retries are allowed, otherwise don't retry
    """

    assert check_checksum(safe_address)

    redis = RedisRepository().redis
    lock_name = f'locks:deploy_create2_safe:{safe_address}'
    try:
        with redis.lock(lock_name, blocking_timeout=1, timeout=LOCK_TIMEOUT):
            try:
                SafeCreationServiceProvider().deploy_create2_safe_tx(safe_address)
            except NotEnoughFundingForCreation:
                if retry:
                    raise self.retry(countdown=30)
    except LockError:
        logger.warning('Cannot get lock={} for deploying safe={}'.format(lock_name, safe_address)) 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:23,代碼來源:tasks.py

示例3: check_pending_transactions

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def check_pending_transactions() -> int:
    """
    Find txs that have not been mined after a while
    :return: Number of pending transactions
    """
    number_txs = 0
    try:
        redis = RedisRepository().redis
        with redis.lock('tasks:check_pending_transactions', blocking_timeout=1, timeout=60):
            tx_not_mined_alert = settings.SAFE_TX_NOT_MINED_ALERT_MINUTES
            txs = SafeMultisigTx.objects.pending(older_than=tx_not_mined_alert * 60)
            for tx in txs:
                logger.error('Tx with tx-hash=%s and safe-tx-hash=%s has not been mined after a while, created=%s',
                             tx.ethereum_tx_id, tx.safe_tx_hash, tx.created)
                number_txs += 1
    except LockError:
        pass
    return number_txs 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:20,代碼來源:tasks.py

示例4: do_extend

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def do_extend(self, additional_time):
        pipe = self.redis.pipeline()
        pipe.watch(self.name)
        lock_value = pipe.get(self.name)
        if lock_value != self.local.token:
            raise LockError("Cannot extend a lock that's no longer owned")
        expiration = pipe.pttl(self.name)
        if expiration is None or expiration < 0:
            # Redis evicted the lock key between the previous get() and now
            # we'll handle this when we call pexpire()
            expiration = 0
        pipe.multi()
        pipe.pexpire(self.name, expiration + int(additional_time * 1000))

        try:
            response = pipe.execute()
        except WatchError:
            # someone else acquired the lock
            raise LockError("Cannot extend a lock that's no longer owned")
        if not response[0]:
            # pexpire returns False if the key doesn't exist
            raise LockError("Cannot extend a lock that's no longer owned")
        return True 
開發者ID:leancloud,項目名稱:satori,代碼行數:25,代碼來源:lock.py

示例5: release_lock

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def release_lock(lock_name, token):
    """
    Release a lock

    Args:
        lock_name (str): The lock key in redis
        token (bytes): The unique id used

    Returns:
        bool: True if the lock was successfully released
    """
    # this is a StrictRedis instance, we need this for the script installation that LuaLock uses
    redis = caches['redis'].client.get_client()
    lock = LuaLock(redis, lock_name)
    try:
        lock.do_release(token)
    except LockError:
        # If the lock is expired we don't want to raise an error
        pass 
開發者ID:mitodl,項目名稱:micromasters,代碼行數:21,代碼來源:locks.py

示例6: check_create2_deployed_safes_task

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def check_create2_deployed_safes_task() -> None:
    """
    Check if create2 safes were deployed and store the `blockNumber` if there are enough confirmations
    """
    try:
        redis = RedisRepository().redis
        with redis.lock('tasks:check_create2_deployed_safes_task', blocking_timeout=1, timeout=LOCK_TIMEOUT):
            ethereum_client = EthereumClientProvider()
            confirmations = 6
            current_block_number = ethereum_client.current_block_number
            for safe_creation2 in SafeCreation2.objects.pending_to_check():
                tx_receipt = ethereum_client.get_transaction_receipt(safe_creation2.tx_hash)
                safe_address = safe_creation2.safe.address
                if tx_receipt:
                    block_number = tx_receipt.blockNumber
                    if (current_block_number - block_number) >= confirmations:
                        logger.info('Safe=%s with tx-hash=%s was confirmed in block-number=%d',
                                    safe_address, safe_creation2.tx_hash, block_number)
                        send_create_notification.delay(safe_address, safe_creation2.owners)
                        safe_creation2.block_number = block_number
                        safe_creation2.save()
                else:
                    # If safe was not included in any block after 35 minutes (mempool limit is 30)
                    # we try to deploy it again
                    if safe_creation2.modified + timedelta(minutes=35) < timezone.now():
                        logger.info('Safe=%s with tx-hash=%s was not deployed after 10 minutes',
                                    safe_address, safe_creation2.tx_hash)
                        safe_creation2.tx_hash = None
                        safe_creation2.save()
                        deploy_create2_safe_task.delay(safe_address, retry=False)

            for safe_creation2 in SafeCreation2.objects.not_deployed().filter(
                    created__gte=timezone.now() - timedelta(days=10)):
                deploy_create2_safe_task.delay(safe_creation2.safe.address, retry=False)
    except LockError:
        pass 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:38,代碼來源:tasks.py

示例7: find_erc_20_721_transfers_task

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def find_erc_20_721_transfers_task() -> int:
    """
    Find and process internal txs for existing safes
    :return: Number of safes processed
    """
    number_safes = 0
    try:
        redis = RedisRepository().redis
        with redis.lock('tasks:find_internal_txs_task', blocking_timeout=1, timeout=60 * 30):
            number_safes = Erc20EventsServiceProvider().process_all()
            logger.info('Find ERC20/721 task processed %d safes', number_safes)
    except LockError:
        pass
    return number_safes 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:16,代碼來源:tasks.py

示例8: close

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def close(self):
        # it would be call after cycle end
        if self.multi_node:
            try:
                self._lock.release()
            except LockError:
                pass
        self.sync() 
開發者ID:liuliqiang,項目名稱:redisbeat,代碼行數:10,代碼來源:scheduler.py

示例9: release

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def release(self):
        "Releases the already acquired lock"
        expected_token = self.local.token
        if expected_token is None:
            raise LockError("Cannot release an unlocked lock")
        self.local.token = None
        self.do_release(expected_token) 
開發者ID:leancloud,項目名稱:satori,代碼行數:9,代碼來源:lock.py

示例10: do_release

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def do_release(self, expected_token):
        name = self.name

        def execute_release(pipe):
            lock_value = pipe.get(name)
            if lock_value != expected_token:
                raise LockError("Cannot release a lock that's no longer owned")
            pipe.delete(name)

        self.redis.transaction(execute_release, name) 
開發者ID:leancloud,項目名稱:satori,代碼行數:12,代碼來源:lock.py

示例11: extend

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def extend(self, additional_time):
        """
        Adds more time to an already acquired lock.

        ``additional_time`` can be specified as an integer or a float, both
        representing the number of seconds to add.
        """
        if self.local.token is None:
            raise LockError("Cannot extend an unlocked lock")
        if self.timeout is None:
            raise LockError("Cannot extend a lock with no timeout")
        return self.do_extend(additional_time) 
開發者ID:leancloud,項目名稱:satori,代碼行數:14,代碼來源:lock.py

示例12: __enter__

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def __enter__(self):
        # force blocking, as otherwise the user would have to check whether
        # the lock was actually acquired or not.
        if self.acquire(blocking=True):
            return self
        raise LockError("Unable to acquire lock within the time specified") 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:8,代碼來源:lock.py

示例13: reacquire

# 需要導入模塊: from redis import exceptions [as 別名]
# 或者: from redis.exceptions import LockError [as 別名]
def reacquire(self):
        """
        Resets a TTL of an already acquired lock back to a timeout value.
        """
        if self.local.token is None:
            raise LockError("Cannot reacquire an unlocked lock")
        if self.timeout is None:
            raise LockError("Cannot reacquire a lock with no timeout")
        return self.do_reacquire() 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:11,代碼來源:lock.py


注:本文中的redis.exceptions.LockError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。