本文整理汇总了Python中curio.run方法的典型用法代码示例。如果您正苦于以下问题:Python curio.run方法的具体用法?Python curio.run怎么用?Python curio.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curio
的用法示例。
在下文中一共展示了curio.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: h2_server
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def h2_server(address, root, certfile, keyfile):
"""
Create an HTTP/2 server at the given address.
"""
sock = await create_listening_ssl_socket(address, certfile, keyfile)
print("Now listening on %s:%d" % address)
async with sock:
while True:
client, _ = await sock.accept()
server = H2Server(client, root)
await spawn(server.run())
示例2: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def run(self):
"""
Loop over the connection, managing it appropriately.
"""
self.conn.initiate_connection()
await self.sock.sendall(self.conn.data_to_send())
while True:
# 65535 is basically arbitrary here: this amounts to "give me
# whatever data you have".
data = await self.sock.recv(65535)
if not data:
break
events = self.conn.receive_data(data)
for event in events:
if isinstance(event, h2.events.RequestReceived):
await spawn(
self.request_received(event.headers, event.stream_id)
)
elif isinstance(event, h2.events.DataReceived):
self.conn.reset_stream(event.stream_id)
elif isinstance(event, h2.events.WindowUpdated):
await self.window_updated(event)
await self.sock.sendall(self.conn.data_to_send())
示例3: _curio_event_run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def _curio_event_run(ble, system):
""" One line function to start the Curio Event loop,
starting all the hubs with the message queue to the bluetooth
communcation thread loop.
Args:
ble : The Adafruit_BluefruitLE interface object
system : Coroutine that the user provided to instantate their system
"""
run(_run_all(ble, system), with_monitor=False)
示例4: start
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def start(user_system_setup_func): #pragma: no cover
"""
Main entry point into running everything.
Just pass in the async co-routine that instantiates all your hubs, and this
function will take care of the rest. This includes:
- Initializing the Adafruit bluetooth interface object
- Starting a run loop inside this bluetooth interface for executing the
Curio event loop
- Starting up the user async co-routines inside the Curio event loop
"""
if USE_BLEAK:
from .bleak_interface import Bleak
ble = Bleak()
# Run curio in a thread
curry_curio_event_run = partial(_curio_event_run, ble=ble, system=user_system_setup_func)
t = threading.Thread(target=curry_curio_event_run)
t.start()
print('started thread for curio')
ble.run()
else:
ble = Adafruit_BluefruitLE.get_provider()
ble.initialize()
# run_mainloop_with call does not accept function args. So let's curry
# the my_run with the ble arg as curry_my_run
curry_curio_event_run = partial(_curio_event_run, ble=ble, system=user_system_setup_func)
ble.run_mainloop_with(curry_curio_event_run)
示例5: bricknil_socket_server
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def bricknil_socket_server(web_out_queue, address): #pragma: no cover
"""Listen for client connections on port 25000 and spawn
`WebClient` instance.
This fuction is spawned as a task during system instantiation
in :func:`bricknil.bricknil._run_all``
"""
async def web_client_connected(client, addr):
logger.info('connection from', addr)
wc = WebClient(client, addr, web_out_queue)
await wc.run()
task = await spawn(tcp_server, '', 25000, web_client_connected, daemon=True)
示例6: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def run(self):
async with self.client:
while True:
msg = await self.in_queue.get()
#print(f'Webclient queue got: {msg}')
await self.in_queue.task_done()
await self.client.sendall(msg)
logger.info('connection closed')
示例7: main
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def main():
result = curio.run(supervisor) # <11>
print('Answer:', result)
示例8: main
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def main():
curio.run(main_coro)
示例9: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def run(callable, *args):
async def _runner():
t = await curio.spawn(thr.thread_handler)
try:
async with curio.spawn_thread():
return callable(*args)
finally:
await t.cancel()
return curio.run(_runner)
示例10: test_sleep
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def test_sleep(self, token):
async def test_function():
delay = 1
start = datetime.datetime.now()
session = asks.Session()
slack_client = SlackAPITrio(session=session, token=token)
await slack_client.sleep(delay)
stop = datetime.datetime.now()
return (
datetime.timedelta(seconds=delay + 1)
> (stop - start)
> datetime.timedelta(seconds=delay)
)
assert trio.run(test_function)
示例11: test__request
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def test__request(self, token):
async def test_function():
session = asks.Session()
slack_client = SlackAPITrio(session=session, token=token)
response = await slack_client._request(
"POST", "https://slack.com/api//api.test", {}, {"token": token}
)
return response[0], response[1]
assert trio.run(test_function) == (200, b'{"ok":false,"error":"invalid_auth"}')
示例12: main
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def main():
result = curio.run(supervisor) # <12>
print('Answer:', result)
示例13: make_request
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def make_request(bind_addr):
async with curio.timeout_after(60):
r = await subprocess.run(
["dig", "+short", f"@{bind_addr[0]}", "-p", f"{bind_addr[1]}", "baidu.com"]
)
assert r.returncode == 0
示例14: test_tunneludp
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def test_tunneludp():
server, bind_addr, _ = get_server(
"tunneludp://127.0.0.1:0?target=1.1.1.1:53&source_ip=in"
)
curio.run(main(bind_addr, server))
示例15: test_ssudp
# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def test_ssudp():
server, bind_addr, _ = get_server("ssudp://chacha20:1@127.0.0.1:0")
address = f"{bind_addr[0]}:{bind_addr[1]}"
server2, bind_addr2, _ = get_server(
f"tunneludp://127.0.0.1:0/?target=1.1.1.1:53&via=ssudp://chacha20:1@{address}"
)
curio.run(main(bind_addr2, server, server2))