How to use curio - 10 common examples

To help you get started, we’ve selected a few curio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github povilasb / udptest / udptest / client.py View on Github external
async def _run_test(self) -> None:
        recv_task = await curio.spawn(self._recv_packets)
        await self._send_packets()
        print('All packets sent')
        try:
            await curio.timeout_after(self._timeout, recv_task.join())
        except curio.TaskTimeout:
            await recv_task.cancel()
github virantha / bricknil / test / test_hub.py View on Github external
def _get_hub_class(self, hub_type, sensor, sensor_name, capabilities):
        stop_evt = Event()
        @attach(sensor, name=sensor_name, capabilities=capabilities)
        class TestHub(hub_type):
            async def sensor_change(self):
                pass
            async def run(self):
                pass
                await stop_evt.wait()

        return TestHub, stop_evt
github dabeaz / curio / tests / test_subprocess.py View on Github external
async def main():
         p = subprocess.Popen([executable, '-c', 'import time;time.sleep(1)'])
         code = await p.wait()
         assert code == 0
github caproto / caproto / tests / epics_test_utils.py View on Github external
Returns
    -------
    stdout, stderr
        Decoded standard output and standard error text
    '''
    args = ['/usr/bin/env'] + list(args)

    print()
    print('* Executing', args)

    epics_env = ca.get_environment_variables()
    env = dict(PATH=os.environ['PATH'],
               EPICS_CA_AUTO_ADDR_LIST=epics_env['EPICS_CA_AUTO_ADDR_LIST'],
               EPICS_CA_ADDR_LIST=epics_env['EPICS_CA_ADDR_LIST'])

    p = curio.subprocess.Popen(args, env=env,
                               stdout=curio.subprocess.PIPE,
                               stderr=curio.subprocess.PIPE)
    await p.wait()
    raw_stdout = await p.stdout.read()
    raw_stderr = await p.stderr.read()
    stdout = raw_stdout.decode('latin-1')
    stderr = raw_stderr.decode('latin-1')
    return stdout, stderr
github povilasb / udptest / udptest / client.py View on Github external
def run(self) -> None:
        try:
            curio.run(self._run_test)
        except KeyboardInterrupt:
            print('Cancelled')
github guyingbo / shadowproxy / tests / test_http_request.py View on Github external
def my_test_ipv6():
    server, bind_addr, _ = get_server("http://user:password@[::1]:0")
    bind_address = f"{bind_addr[0]}:{bind_addr[1]}"
    client = get_client(f"http://user:password@{bind_address}")
    curio.run(main(make_request(client), server))
github dabeaz / curio / tests / test_channel.py View on Github external
async def main(ch1, ch2):
        async with ch1, ch2:
            t1 = await spawn(server, ch1)
            t2 = await spawn(client, ch2)
            await t1.join()
            await t2.join()
github povilasb / udptest / udptest / server.py View on Github external
async def _on_data(self, data: bytes, addr: Tuple[str, int]) -> None:
        task = await curio.spawn(self._sock.sendto, b'response', addr)
        await self._tasks.put(task)
github caproto / caproto / tests / test_curio_server.py View on Github external
async def task():
        server_task = await curio.spawn(curio_server)

        try:
            await client()
        finally:
            await server_task.cancel()
github caproto / caproto / tests / test_bench.py View on Github external
break
                    pvname = res.result
                    await connect_task.spawn(ctx.create_channel, pvname)

            while True:
                res = await connect_task.next_done()
                if res is None:
                    break
                curio_channel = res.result
                pvname = curio_channel.channel.name
                pvs[pvname] = curio_channel

        assert len(pvs) == len(pv_names)
        # TODO: can't successfully test as this hammers file creation; this
        # will be important to resolve...
        await curio.sleep(1)