当前位置: 首页>>代码示例>>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;未经允许,请勿转载。