Skip to content
Myr

concurrency.py

This file

Path

tests/concurrency.py

37 lines · 985 bytes · Python

Last changed by

Drop `run` and `run_in_threadpool` (#710)Tom Christiebefore adoption6ac49da

History of this file

Take it

1"""2This module contains concurrency utilities that are only used in tests, thus not3required as part of the ConcurrencyBackend API.4"""56import asyncio78import sniffio9import trio101112async def sleep(seconds: float):13    if sniffio.current_async_library() == "trio":14        await trio.sleep(seconds)15    else:16        await asyncio.sleep(seconds)171819async def run_concurrently(*coroutines):20    if sniffio.current_async_library() == "trio":21        async with trio.open_nursery() as nursery:22            for coroutine in coroutines:23                nursery.start_soon(coroutine)24    else:25        coros = (coroutine() for coroutine in coroutines)26        await asyncio.gather(*coros)272829def get_cipher(stream):30    if sniffio.current_async_library() == "trio":31        return (32            stream.stream.cipher()33            if isinstance(stream.stream, trio.SSLStream)34            else None35        )36    else:37        return stream.stream_writer.get_extra_info("cipher", default=None)