Skip to content
Myr

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 file

Take it

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

lines 1–7why, one step back
1"""
2This module contains concurrency utilities that are only used in tests, thus not3required as part of the ConcurrencyBackend API.4"""56import asyncio7import functools

Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e

line 8why, one step back
8import typing

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 9why, one step back
9

Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e

lines 10–11why, one step back
10import trio
11

Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b

line 12why, one step back
12from httpx.concurrency.asyncio import AsyncioBackend

Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e

line 13why, one step back
13from httpx.concurrency.trio import TrioBackend

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

lines 14–23why, one step back
14
1516@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 back
24
25

Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e

lines 26–28why, one step back
26@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 back
29

Fix race condition on stream.read (#535)Florimond Mancabefore adoptiona05ba2e

lines 30–46why, one step back
30
31@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)