How to use the curio.TaskGroup function in curio

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 theelous3 / asks / tests / test_asks_curio.py View on Github external
async def test_hsession_smallpool():
    from asks.sessions import Session
    s = Session('http://httpbin.org', connections=2)
    async with curio.TaskGroup() as g:
        for _ in range(10):
            await g.spawn(hsession_t_smallpool(s))
github guyingbo / shadowproxy / tests / test_http_request.py View on Github external
async def main(coro, *server_coros):
    async with curio.TaskGroup() as g:
        for server_coro in server_coros:
            await g.spawn(server_coro)
        task = await g.spawn(coro)
        await task.join()
        await g.cancel_remaining()
github dabeaz / curio / tests / test_channel.py View on Github external
async def main(c1, c2):
        async with TaskGroup() as g:
            await g.spawn(server, c1)
            await g.spawn(client, c2)
github dabeaz / curio / tests / test_channel.py View on Github external
async def main(ch1, ch2):
        async with TaskGroup() as g:
            await g.spawn(server, ch1)
            await g.spawn(client, ch2)
github dabeaz / curio / tests / test_channel.py View on Github external
async def main(c1, c2):
        async with TaskGroup() as g:
            await g.spawn(server, c1)
            await g.spawn(client, c2)
github dabeaz / curio / tests / test_channel.py View on Github external
async def main(ch1, ch2):
        async with TaskGroup() as g:
            await g.spawn(server, ch1)
            await g.spawn(client, ch2)
github guyingbo / shadowproxy / shadowproxy / proxies / base / server.py View on Github external
async def relay(self, via_client):
        try:
            async with curio.TaskGroup() as g:
                await g.spawn(self._relay(via_client))
                await g.spawn(self._reverse_relay(via_client))
                await g.next_done(cancel_remaining=True)
        except curio.TaskGroupError as e:
            gvars.logger.debug(f"group error: {e}")
github trollfot / trinket / src / trinket / websockets.py View on Github external
async def recv(self):
        if not self.closed:
            async with TaskGroup(wait=any) as g:
                receiver = await g.spawn(self.incoming.get)
                await g.spawn(self.closing.wait)
            if g.completed is receiver:
                return receiver.result
github SciCrunch / scibot / scibot / sync.py View on Github external
encoded = syncword.encode()
    currently_running_urls = set()
    async def listen_for_new_conns(task_group):
        while True:
            ch = Channel(chan)
            try:
                connection = await ch.accept(authkey=encoded)
                mlog.info(f'new connection created {connection}')
                await task_group.spawn(manage_single_connection,
                                       connection,
                                       currently_running_urls)
                await ch.close()  # sort of strange that we need this? can we connect again later !?
            except ConnectionResetError as e:
                mlog.warning('client connection attempt did not terminate property')

    async with TaskGroup(name='manager') as connection_tasks:
        await connection_tasks.spawn(exit, connection_tasks)
        await connection_tasks.spawn(listen_for_new_conns, connection_tasks)
github caproto / caproto / caproto / curio / client.py View on Github external
async def create_many_outer():
            async with curio.TaskGroup() as task:
                for name in names:
                    await task.spawn(connect_one, name)
                while True:
                    res = await task.next_done()
                    if res is None:
                        break

                    name, chan = res.result
                    channels[name] = chan