本文整理汇总了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 = {}
示例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?
示例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()
示例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)
示例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())
示例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()
示例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 ---------------------------
示例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)
示例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)
示例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)
示例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)
示例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
示例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
示例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)
示例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