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


Python asyncio.Event方法代码示例

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


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

示例1: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def __init__(self, **kwargs):
        self.heroku_api_token = os.environ.get("heroku_api_token")
        self.api_token = kwargs.pop("api_token")
        self.redirect_url = None
        super().__init__(**kwargs)
        self.app.router.add_get("/initialSetup", self.initial_setup)
        self.app.router.add_put("/setApi", self.set_tg_api)
        self.app.router.add_post("/sendTgCode", self.send_tg_code)
        self.app.router.add_post("/tgCode", self.tg_code)
        self.app.router.add_post("/finishLogin", self.finish_login)
        self.api_set = asyncio.Event()
        self.sign_in_clients = {}
        self.clients = []
        self.clients_set = asyncio.Event()
        self.root_redirected = asyncio.Event()
        self._pending_secret_to_uid = {} 
开发者ID:friendly-telegram,项目名称:friendly-telegram,代码行数:18,代码来源:initial_setup.py

示例2: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def __init__(self, backend, noop=False):
        super().__init__()
        self._noop = noop or backend is None
        self._backend = backend
        self._pending = None
        self._loading = True
        self._waiter = asyncio.Event()
        self._sync_future = None
        # We use a future because we need await-ability and we will be delaying by 10s, but
        # because we are gonna frequently be changing the data, we want to avoid floodwait
        # and to do that we will discard most requests. However, attempting to await any request
        # should return a future corresponding to the next time that we flush the database.
        # To achieve this, we have one future stored here (the next time we flush the db) and we
        # always return that from set(). However, if someone decides to await set() much later
        # than when they called set(), it will already be finished. Luckily, we return a future,
        # not a reference to _sync_future, so it will be the correct future, and set_result will
        # not already have been called. Simple, right? 
开发者ID:friendly-telegram,项目名称:friendly-telegram,代码行数:19,代码来源:frontend.py

示例3: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def __init__(
        self, expected_content_length: Optional[int], max_content_length: Optional[int]
    ) -> None:
        self._data = bytearray()
        self._complete: asyncio.Event = asyncio.Event()
        self._has_data: asyncio.Event = asyncio.Event()
        self._max_content_length = max_content_length
        # Exceptions must be raised within application (not ASGI)
        # calls, this is achieved by having the ASGI methods set this
        # to an exception on error.
        self._must_raise: Optional[Exception] = None
        if (
            expected_content_length is not None
            and max_content_length is not None
            and expected_content_length > max_content_length
        ):
            from ..exceptions import RequestEntityTooLarge  # noqa Avoiding circular import

            self._must_raise = RequestEntityTooLarge() 
开发者ID:pgjones,项目名称:quart,代码行数:21,代码来源:request.py

示例4: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def __init__(self, app, reportrate=1):
        self.app = app
        self.proto = None
        self.timer = None
        self._fragment = None
        self.abort_stream = False
        self.pause_stream = False  # asyncio.Event()
        self.okcnt = None
        self.ping_pong = True  # ping pong protocol for streaming
        self.file_streamer = None
        self.report_rate = reportrate
        self._reroute_incoming_data_to = None
        self._restart_timer = False
        self.is_streaming = False
        self.do_query = False
        self.last_tool = None
        self.is_suspend = False
        self.m0 = None
        self.net_connection = False
        self.log = logging.getLogger()  # .getChild('Comms')
        # logging.getLogger().setLevel(logging.DEBUG) 
开发者ID:wolfmanjm,项目名称:kivy-smoothie-host,代码行数:23,代码来源:comms.py

示例5: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [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

示例6: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def __init__(self, loop: asyncio.AbstractEventLoop, **kwargs):
        auth_headers = {
            'Authorization': f"Token {Keys.site_api}"
        }

        if 'headers' in kwargs:
            kwargs['headers'].update(auth_headers)
        else:
            kwargs['headers'] = auth_headers

        self.session = None
        self.loop = loop

        self._ready = asyncio.Event(loop=loop)
        self._creation_task = None
        self._default_session_kwargs = kwargs

        self.recreate() 
开发者ID:python-discord,项目名称:bot,代码行数:20,代码来源:api.py

示例7: test_can_receive_binary_data_from_connection

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def test_can_receive_binary_data_from_connection(tcp_connection_class,
                                                       integration_tcp_server_and_pipe):
    from moler.threaded_moler_connection import ThreadedMolerConnection
    (tcp_server, tcp_server_pipe) = integration_tcp_server_and_pipe
    received_data = bytearray()
    receiver_called = asyncio.Event()

    def receiver(data, time_recv):
        received_data.extend(data)
        receiver_called.set()

    moler_conn = ThreadedMolerConnection()  # no decoder, just pass bytes 1:1
    moler_conn.subscribe(receiver)       # build forwarding path
    connection = tcp_connection_class(moler_connection=moler_conn, port=tcp_server.port, host=tcp_server.host)
    async with connection:  # TODO: async with connection.open():
        time.sleep(0.1)  # otherwise we have race between server's pipe and from-client-connection
        tcp_server_pipe.send(("send async msg", {'msg': b'data to read'}))
        await asyncio.wait_for(receiver_called.wait(), timeout=0.5)

    assert b'data to read' == received_data


# TODO: tests for error cases raising Exceptions

# --------------------------- resources --------------------------- 
开发者ID:nokia,项目名称:moler,代码行数:27,代码来源:py3test_io_tcp.py

示例8: test_election_early_wait_for_leadership

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def test_election_early_wait_for_leadership(zk, path):
    elec = zk.recipes.LeaderElection(path)

    early_wait_success = asyncio.Event()

    async def wait_early():
        await elec.wait_for_leadership()
        assert elec.has_leadership
        early_wait_success.set()

    asyncio.create_task(wait_early())
    await asyncio.sleep(0.5)
    assert not elec.has_leadership

    await elec.volunteer()

    # NO WAIT
    await asyncio.wait_for(early_wait_success.wait(), timeout=0.5)

    await elec.resign()

    assert not elec.has_leadership

    await zk.delete(path) 
开发者ID:micro-fan,项目名称:aiozk,代码行数:26,代码来源:test_election.py

示例9: test_data_watch

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def test_data_watch(zk, path, data_watcher):
    data = []
    ready = asyncio.Event()
    test_data = b'test' * 1000

    async def data_callback(d):
        data.append(d)
        ready.set()

    data_watcher.add_callback(path, data_callback)
    assert data == []
    await zk.set_data(path, test_data)
    await asyncio.wait_for(ready.wait(), timeout=0.1)
    assert ready.is_set()
    assert data == [test_data]
    data_watcher.remove_callback(path, data_callback) 
开发者ID:micro-fan,项目名称:aiozk,代码行数:18,代码来源:test_watchers.py

示例10: test_data_watch_delete

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def test_data_watch_delete(zk, path, data_watcher):
    data = []
    ready = asyncio.Event()
    test_data = b'test'

    async def data_callback(d):
        data.append(d)
        ready.set()

    await zk.set_data(path, test_data)

    data_watcher.add_callback(path, data_callback)
    await asyncio.sleep(0.2)
    assert data == [test_data]
    ready.clear()
    await zk.delete(path)

    await asyncio.wait_for(ready.wait(), timeout=1)
    assert ready.is_set()
    assert data == [test_data, NoNode]
    data_watcher.remove_callback(path, data_callback)

    await zk.create(path) 
开发者ID:micro-fan,项目名称:aiozk,代码行数:25,代码来源:test_watchers.py

示例11: test_child_watch

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def test_child_watch(child_watcher, path, zk, child1, child2):
    children = set()
    ready = asyncio.Event()

    async def children_callback(c):
        for child in c:
            children.add(child)
            ready.set()

    child_watcher.add_callback(path, children_callback)
    assert children == set()
    await zk.create(child1)
    await asyncio.wait([ready.wait()], timeout=0.1)
    assert children == {child1.split('/')[-1]}
    ready.clear()
    await zk.create(child2)
    await asyncio.wait([ready.wait()], timeout=0.1)
    assert ready.is_set()
    assert children == {child.split('/')[-1] for child in (child1, child2)}
    child_watcher.remove_callback(path, children_callback) 
开发者ID:micro-fan,项目名称:aiozk,代码行数:22,代码来源:test_watchers.py

示例12: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [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

示例13: wait_ping

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def wait_ping(self, remote: kademlia.Node) -> bool:
        """Wait for a ping from the given remote.

        This coroutine adds a callback to ping_callbacks and yields control until that callback is
        called or a timeout (k_request_timeout) occurs. At that point it returns whether or not
        a ping was received from the given node.
        """
        event = asyncio.Event()

        with self.ping_callbacks.acquire(remote, event.set):
            got_ping = False
            try:
                got_ping = await self.cancel_token.cancellable_wait(
                    event.wait(), timeout=kademlia.k_request_timeout
                )
                self.logger.trace("got expected ping from %s", remote)
            except TimeoutError:
                self.logger.trace("timed out waiting for ping from %s", remote)

        return got_ping 
开发者ID:QuarkChain,项目名称:pyquarkchain,代码行数:22,代码来源:discovery.py

示例14: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def __init__(
        self,
        proxy_conn,
        op_ser_map,
        op_non_rpc_map,
        op_rpc_map,
        loop=None,
        metadata_class=Metadata,
        name=None,
    ):
        super().__init__(
            op_ser_map, op_non_rpc_map, op_rpc_map, loop, metadata_class, name=name
        )
        self.read_deque = deque()
        self.read_event = asyncio.Event()
        self.proxy_conn = proxy_conn
        self.forward_conn = ForwardingVirtualConnection(self) 
开发者ID:QuarkChain,项目名称:pyquarkchain,代码行数:19,代码来源:protocol.py

示例15: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Event [as 别名]
def __init__(self, loop, client: BleakClient, client_mac: str, device_mac: str, key: bytes):
        self.state: BandState = BandState.Disconnected

        self.client: BleakClient = client
        self.loop = loop

        self.client_mac: str = client_mac
        self.device_mac: str = device_mac
        self.client_serial: str = client_mac.replace(":", "")[-6:]  # android.os.Build.SERIAL

        self._key: bytes = key
        self._server_nonce: Optional[bytes] = None
        self._client_nonce: bytes = generate_nonce()
        self._encryption_counter: int = 0

        self.link_params: Optional[device_config.LinkParams] = None

        self.bond_status: Optional[int] = None
        self.bond_status_info: Optional[int] = None
        self.bt_version: Optional[int] = None

        self._packet: Optional[Packet] = None
        self._event = asyncio.Event()
        self.__message_id: int = -1 
开发者ID:zyv,项目名称:huawei-lpv2,代码行数:26,代码来源:band_lpv2.py


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