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


Python curio.run方法代码示例

本文整理汇总了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()) 
开发者ID:python-hyper,项目名称:hyper-h2,代码行数:14,代码来源:curio-server.py

示例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()) 
开发者ID:python-hyper,项目名称:hyper-h2,代码行数:28,代码来源:curio-server.py

示例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) 
开发者ID:virantha,项目名称:bricknil,代码行数:13,代码来源:bricknil.py

示例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) 
开发者ID:virantha,项目名称:bricknil,代码行数:32,代码来源:bricknil.py

示例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) 
开发者ID:virantha,项目名称:bricknil,代码行数:14,代码来源:sockets.py

示例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') 
开发者ID:virantha,项目名称:bricknil,代码行数:11,代码来源:sockets.py

示例7: main

# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def main():
    result = curio.run(supervisor)  # <11>
    print('Answer:', result) 
开发者ID:fluentpython,项目名称:concurrency2017,代码行数:5,代码来源:spinner_curio.py

示例8: main

# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def main():
    curio.run(main_coro) 
开发者ID:standy66,项目名称:purerpc,代码行数:4,代码来源:client.py

示例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) 
开发者ID:dabeaz,项目名称:thredo,代码行数:11,代码来源:core.py

示例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) 
开发者ID:pyslackers,项目名称:slack-sansio,代码行数:17,代码来源:test_io.py

示例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"}') 
开发者ID:pyslackers,项目名称:slack-sansio,代码行数:12,代码来源:test_io.py

示例12: main

# 需要导入模块: import curio [as 别名]
# 或者: from curio import run [as 别名]
def main():
    result = curio.run(supervisor)  # <12>
    print('Answer:', result) 
开发者ID:fluentpython,项目名称:example-code,代码行数:5,代码来源:spinner_curio.py

示例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 
开发者ID:guyingbo,项目名称:shadowproxy,代码行数:8,代码来源:test_udp.py

示例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)) 
开发者ID:guyingbo,项目名称:shadowproxy,代码行数:7,代码来源:test_udp.py

示例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)) 
开发者ID:guyingbo,项目名称:shadowproxy,代码行数:9,代码来源:test_udp.py


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