concurrency.py
This file
Path
tests/concurrency.py
46 lines · 1.2 KiB · Python
Last changed by
Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
History of this fileTake it
Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 1–7why, one step back1"""2This module contains concurrency utilities that are only used in tests, thus not3required as part of the ConcurrencyBackend API.4"""56import asyncio7import functoolsFix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
line 8why, one step back8import typingParametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 9why, one step back9Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
lines 10–11why, one step back10import trio11Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 12why, one step back12from httpx.concurrency.asyncio import AsyncioBackendFix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
line 13why, one step back13from httpx.concurrency.trio import TrioBackendParametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 14–23why, one step back141516@functools.singledispatch17async def sleep(backend, seconds: int):18 raise NotImplementedError # pragma: no cover192021@sleep.register(AsyncioBackend)22async def _sleep_asyncio(backend, seconds: int):23 await asyncio.sleep(seconds)Add trio concurrency backend (#276)Florimond Mancabefore adoption08355c6
lines 24–25why, one step back2425Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
lines 26–28why, one step back26@sleep.register(TrioBackend)27async def _sleep_trio(backend, seconds: int):28 await trio.sleep(seconds)Add trio concurrency backend (#276)Florimond Mancabefore adoption08355c6
line 29why, one step back29Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e
lines 30–46why, one step back3031@functools.singledispatch32async def run_concurrently(backend, *coroutines: typing.Callable[[], typing.Awaitable]):33 raise NotImplementedError # pragma: no cover343536@run_concurrently.register(AsyncioBackend)37async def _run_concurrently_asyncio(backend, *coroutines):38 coros = (coroutine() for coroutine in coroutines)39 await asyncio.gather(*coros)404142@run_concurrently.register(TrioBackend)43async def _run_concurrently_trio(backend, *coroutines):44 async with trio.open_nursery() as nursery:45 for coroutine in coroutines:46 nursery.start_soon(coroutine)