当前位置: 首页>>代码示例>>Python>>正文


Python asyncio.Lock方法代码示例

本文整理汇总了Python中asyncio.Lock方法的典型用法代码示例。如果您正苦于以下问题:Python asyncio.Lock方法的具体用法?Python asyncio.Lock怎么用?Python asyncio.Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在asyncio的用法示例。


在下文中一共展示了asyncio.Lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _async_send

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def _async_send(self, request: Request):
        if request.method.lower() != 'get':
            return await self.sender.send(request)

        if self._lock is None:
            self._lock = asyncio.Lock()

        async with self._lock:
            cached, etag = self._load(request)

        if cached is not None and etag is None:
            return cached
        elif etag is not None:
            request.headers.update(ETag=etag)

        fresh = await self.sender.send(request)
        async with self._lock:
            return self._handle_fresh(request, fresh, cached) 
开发者ID:felix-hilden,项目名称:tekore,代码行数:20,代码来源:extending.py

示例2: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(self, bot: Bot):
        super().__init__()

        self.bot = bot

        # Categories
        self.available_category: discord.CategoryChannel = None
        self.in_use_category: discord.CategoryChannel = None
        self.dormant_category: discord.CategoryChannel = None

        # Queues
        self.channel_queue: asyncio.Queue[discord.TextChannel] = None
        self.name_queue: t.Deque[str] = None

        self.name_positions = self.get_names()
        self.last_notification: t.Optional[datetime] = None

        # Asyncio stuff
        self.queue_tasks: t.List[asyncio.Task] = []
        self.ready = asyncio.Event()
        self.on_message_lock = asyncio.Lock()
        self.init_task = self.bot.loop.create_task(self.init_cog()) 
开发者ID:python-discord,项目名称:bot,代码行数:24,代码来源:help_channels.py

示例3: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(self, hostname, sasl,
                 container_id=False,
                 max_frame_size=None,
                 channel_max=None,
                 idle_timeout=None,
                 properties=None,
                 remote_idle_timeout_empty_frame_send_ratio=None,
                 error_policy=None,
                 debug=False,
                 encoding='UTF-8',
                 loop=None):
        self.loop = loop or get_running_loop()
        super(ConnectionAsync, self).__init__(
            hostname, sasl,
            container_id=container_id,
            max_frame_size=max_frame_size,
            channel_max=channel_max,
            idle_timeout=idle_timeout,
            properties=properties,
            remote_idle_timeout_empty_frame_send_ratio=remote_idle_timeout_empty_frame_send_ratio,
            error_policy=error_policy,
            debug=debug,
            encoding=encoding)
        self._async_lock = asyncio.Lock(loop=self.loop) 
开发者ID:Azure,项目名称:azure-uamqp-python,代码行数:26,代码来源:connection_async.py

示例4: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(self, connection):
        """
        Constructs this handler on a given validator connection.

        Args:
            connection (messaging.Connection): the validator connection
        """
        self._connection = connection

        self._latest_state_delta_event = None
        self._subscribers = []
        self._subscriber_lock = asyncio.Lock()
        self._delta_task = None
        self._listening = False
        self._accepting = True

        self._connection.on_connection_state_change(
            ConnectionEvent.DISCONNECTED,
            self._handle_disconnect)
        self._connection.on_connection_state_change(
            ConnectionEvent.RECONNECTED,
            self._handle_reconnection) 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:24,代码来源:state_delta_subscription_handler.py

示例5: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(self, stream_id, window_getter, loop=None):
        if loop is None:
            loop = asyncio.get_event_loop()
        self._stream_id = stream_id
        self._window_getter = window_getter

        self._wlock = asyncio.Lock(loop=loop)
        self._window_open = CallableEvent(self._is_window_open, loop=loop)

        self._rlock = asyncio.Lock(loop=loop)
        self._buffers = deque()
        self._buffer_size = 0
        self._buffer_ready = asyncio.Event(loop=loop)
        self._response = asyncio.Future(loop=loop)
        self._trailers = asyncio.Future(loop=loop)
        self._eof_received = False
        self._closed = False 
开发者ID:decentfox,项目名称:aioh2,代码行数:19,代码来源:protocol.py

示例6: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(
        self, token: CancelToken = None, loop: asyncio.AbstractEventLoop = None
    ) -> None:
        self.events = ServiceEvents()
        self._run_lock = asyncio.Lock()
        self._child_services = WeakSet()
        self._tasks = WeakSet()
        self._finished_callbacks = []

        self._loop = loop

        base_token = CancelToken(type(self).__name__, loop=loop)

        if token is None:
            self.cancel_token = base_token
        else:
            self.cancel_token = base_token.chain(token) 
开发者ID:QuarkChain,项目名称:pyquarkchain,代码行数:19,代码来源:service.py

示例7: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(self, config, queue, events, loop=None):
        """
        Initialize instance of the NodeManager class

        :param config: config object
        :param queue: broadcast queue
        :type config: tattle.config.Configuration
        :type events: tattle.event.EventManager
        :type queue: tattle.queue.BroadcastQueue
        """
        self.config = config
        self._queue = queue
        self._events = events
        self._loop = loop or asyncio.get_event_loop()
        self._leaving = False
        self._nodes = list()
        self._nodes_map = dict()
        self._nodes_lock = asyncio.Lock()
        self._suspect_nodes = dict()
        self._local_node_name = None
        self._local_node_seq = sequence.Sequence() 
开发者ID:kippandrew,项目名称:tattle,代码行数:23,代码来源:state.py

示例8: _cache_instances

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def _cache_instances(self, region: str):
        async with self._regional_instances_cache_locks.setdefault(region, Lock()):
            if region in self._instances_cache:
                return

            self._instances_cache[region] = await AWSFacadeUtils.get_all_pages(
                'rds', region, self.session, 'describe_db_instances', 'DBInstances')

            for instance in self._instances_cache[region]:
                instance['VpcId'] = instance['DBSubnetGroup']['VpcId'] \
                    if 'DBSubnetGroup' in instance and 'VpcId' in instance['DBSubnetGroup'] \
                    and instance['DBSubnetGroup']['VpcId'] \
                    else ec2_classic

            await get_and_set_concurrently(
                [self._get_and_set_instance_clusters, self._get_and_set_instance_tags], self._instances_cache[region], region=region) 
开发者ID:nccgroup,项目名称:ScoutSuite,代码行数:18,代码来源:rds.py

示例9: cache_load_balancers

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def cache_load_balancers(self, region):
        async with self.regional_load_balancers_cache_locks.setdefault(region, asyncio.Lock()):
            if region in self.load_balancers_cache:
                return

            self.load_balancers_cache[region] = \
                await AWSFacadeUtils.get_all_pages('elb', region, self.session,
                                                   'describe_load_balancers', 'LoadBalancerDescriptions')

            for load_balancer in self.load_balancers_cache[region]:
                load_balancer['VpcId'] = \
                    load_balancer['VPCId'] if 'VPCId' in load_balancer and load_balancer['VPCId'] else ec2_classic

            await get_and_set_concurrently(
                [self._get_and_set_load_balancer_attributes], self.load_balancers_cache[region], region=region)

            await get_and_set_concurrently(
                [self._get_and_set_load_balancer_tags], self.load_balancers_cache[region], region=region) 
开发者ID:nccgroup,项目名称:ScoutSuite,代码行数:20,代码来源:elb.py

示例10: cache_load_balancers

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def cache_load_balancers(self, region):
        async with self.regional_load_balancers_cache_locks.setdefault(region, asyncio.Lock()):
            if region in self.load_balancers_cache:
                return

            self.load_balancers_cache[region] = \
                await AWSFacadeUtils.get_all_pages('elbv2', region, self.session,
                                                   'describe_load_balancers', 'LoadBalancers')

            for load_balancer in self.load_balancers_cache[region]:
                load_balancer['VpcId'] = \
                    load_balancer['VpcId'] if 'VpcId' in load_balancer and load_balancer['VpcId'] else ec2_classic

            await get_and_set_concurrently(
                [self._get_and_set_load_balancer_attributes], self.load_balancers_cache[region], region=region)

            await get_and_set_concurrently(
                [self._get_and_set_load_balancer_tags], self.load_balancers_cache[region], region=region) 
开发者ID:nccgroup,项目名称:ScoutSuite,代码行数:20,代码来源:elbv2.py

示例11: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(self, period=DEFAULT_THROTTLE, params=[], log=True, count=1):
		self.period = period
		self.watchparams = params
		self.lastrun = {}
		self.lastreturn = {}
		self.lastcleanup = time.time()
		self.log = log
		self.count = count
		self.lock = asyncio.Lock()

		# need to decorate this here, rather than putting a decorator on the actual
		# function, as it needs to wrap the *bound* method, so there's no "self"
		# parameter. Meanwhile, we're wrapping this "decorate" function instead of
		# just wrapping __call__ as setting __call__ directly on instances doesn't
		# work, Python gets the __call__ function from the class, not individual
		# instances.
		self.decorate = coro_decorator(self.decorate) 
开发者ID:mrphlip,项目名称:lrrbot,代码行数:19,代码来源:utils.py

示例12: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(self, host=None, listen=15):
        assert V.DATA_PATH is not None, 'Setup p2p params before CoreClass init.'
        assert host is None or host == 'localhost'
        # status params
        self.f_stop = False
        self.f_finish = False
        self.f_running = False
        # working info
        self.start_time = int(time())
        self.number = 0
        self.user: List[User] = list()
        self.user_lock = asyncio.Lock()
        self.host = host  # local=>'localhost', 'global'=>None
        self.core_que = asyncio.Queue()
        self.backlog = listen
        self.traffic = Traffic()
        self.ping_status: Dict[int, asyncio.Event] = ExpiringDict(max_len=5000, max_age_seconds=900) 
开发者ID:namuyan,项目名称:p2p-python,代码行数:19,代码来源:core.py

示例13: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(self,
                 topic: Optional[str] = None,
                 max_connections: int = 10,
                 max_connection_attempts: Optional[int] = None,
                 loop: Optional[asyncio.AbstractEventLoop] = None,
                 use_sandbox: bool = False):

        self.apns_topic = topic
        self.max_connections = max_connections
        if use_sandbox:
            self.protocol_class = APNsDevelopmentClientProtocol
        else:
            self.protocol_class = APNsProductionClientProtocol

        self.loop = loop or asyncio.get_event_loop()
        self.connections = []
        self._lock = asyncio.Lock(loop=self.loop)
        self.max_connection_attempts = max_connection_attempts 
开发者ID:Fatal1ty,项目名称:aioapns,代码行数:20,代码来源:connection.py

示例14: add_item

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def add_item(self, success_cb_id, firstname, lastname, date,
                 source, destination, train_num, ct_letter=None):
        scan_id = uuid4().hex
        self.__state[scan_id] = dict(
            success_cb_id=success_cb_id,
            firstname=firstname,
            lastname=lastname,
            date=date,
            source=source,
            destination=destination,
            train_num=train_num,
            ct_letter=ct_letter,
            lock=asyncio.Lock(),
            attempts=0,
            error=None)
        return scan_id 
开发者ID:vit-,项目名称:telegram-uz-bot,代码行数:18,代码来源:scanner.py

示例15: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Lock [as 别名]
def __init__(self, event_loop, session_name, api_id, api_hash, phone_number, workdir=None):

        self.event_loop = event_loop
        self.username_flood_until = None
        self._message_intervals = {}
        self._last_ping = None
        self.__photos_lock = asyncio.Lock(loop=self.event_loop)

        super(BotChecker, self).__init__(
            session_name,
            api_id,
            api_hash,
            workers=4,
            phone_number=phone_number,
            workdir=workdir
        )
        self.logger.setLevel(logging.WARNING) 
开发者ID:JosXa,项目名称:BotListBot,代码行数:19,代码来源:botchecker.py


注:本文中的asyncio.Lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。