]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Drop 'fork' (#619)
authorTom Christie <tom@tomchristie.com>
Sun, 8 Dec 2019 19:52:46 +0000 (19:52 +0000)
committerGitHub <noreply@github.com>
Sun, 8 Dec 2019 19:52:46 +0000 (19:52 +0000)
httpx/concurrency/asyncio.py
httpx/concurrency/auto.py
httpx/concurrency/base.py
httpx/concurrency/trio.py
tests/test_concurrency.py

index 51006959f5c9e053dae3532549ef9ccf1e9ce666..39bccdc933254448bcde554ecd2f7a2f984e078b 100644 (file)
@@ -268,28 +268,6 @@ class AsyncioBackend(ConcurrencyBackend):
         finally:
             self._loop = loop
 
-    async def fork(
-        self,
-        coroutine1: typing.Callable,
-        args1: typing.Sequence,
-        coroutine2: typing.Callable,
-        args2: typing.Sequence,
-    ) -> None:
-        task1 = self.loop.create_task(coroutine1(*args1))
-        task2 = self.loop.create_task(coroutine2(*args2))
-
-        try:
-            await asyncio.gather(task1, task2)
-        finally:
-            pending: typing.Set[asyncio.Future[typing.Any]]  # Please mypy.
-            _, pending = await asyncio.wait({task1, task2}, timeout=0)
-            for task in pending:
-                task.cancel()
-                try:
-                    await task
-                except asyncio.CancelledError:
-                    pass
-
     def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore:
         return PoolSemaphore(limits)
 
index ed85806e7a3361062f2403e2eb1cae43388198e9..3b57e5674dde029d01019ad3da115722f5865ae0 100644 (file)
@@ -51,12 +51,3 @@ class AutoBackend(ConcurrencyBackend):
 
     def create_event(self) -> BaseEvent:
         return self.backend.create_event()
-
-    async def fork(
-        self,
-        coroutine1: typing.Callable,
-        args1: typing.Sequence,
-        coroutine2: typing.Callable,
-        args2: typing.Sequence,
-    ) -> None:
-        return await self.backend.fork(coroutine1, args1, coroutine2, args2)
index 27ce9c89bd098ddc587f5a39d83ee4d923c09718..a735c87e73872af582738fe83e1cd05d30857af7 100644 (file)
@@ -120,21 +120,3 @@ class ConcurrencyBackend:
 
     def create_event(self) -> BaseEvent:
         raise NotImplementedError()  # pragma: no cover
-
-    async def fork(
-        self,
-        coroutine1: typing.Callable,
-        args1: typing.Sequence,
-        coroutine2: typing.Callable,
-        args2: typing.Sequence,
-    ) -> None:
-        """
-        Run two coroutines concurrently.
-
-        This should start 'coroutine1' with '*args1' and 'coroutine2' with '*args2',
-        and wait for them to finish.
-
-        In case one of the coroutines raises an exception, cancel the other one then
-        raise. If the other coroutine had also raised an exception, ignore it.
-        """
-        raise NotImplementedError()  # pragma: no cover
index 7604e965ab14d7ca98d2e1489faa3a8d641a2139..4fa3001983f341c9cb45ddf4646a1b451a022cac 100644 (file)
@@ -168,22 +168,6 @@ class TrioBackend(ConcurrencyBackend):
             functools.partial(coroutine, **kwargs) if kwargs else coroutine, *args
         )
 
-    async def fork(
-        self,
-        coroutine1: typing.Callable,
-        args1: typing.Sequence,
-        coroutine2: typing.Callable,
-        args2: typing.Sequence,
-    ) -> None:
-        try:
-            async with trio.open_nursery() as nursery:
-                nursery.start_soon(coroutine1, *args1)
-                nursery.start_soon(coroutine2, *args2)
-        except trio.MultiError as exc:
-            # In practice, we don't actually care about raising both
-            # exceptions, so let's raise either indeterminantly.
-            raise exc.exceptions[0]
-
     def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore:
         return PoolSemaphore(limits)
 
index 3e3d64030c2aa6c9783bb8092dece452d956202a..a9b23dc37f0e73aaea12ebf6f8ee24f204f706e6 100644 (file)
@@ -8,7 +8,7 @@ from httpx.concurrency.asyncio import AsyncioBackend
 from httpx.concurrency.base import lookup_backend
 from httpx.concurrency.trio import TrioBackend
 from httpx.config import SSLConfig
-from tests.concurrency import get_cipher, run_concurrently, sleep
+from tests.concurrency import get_cipher, run_concurrently
 
 
 async def read_response(stream, timeout: Timeout, should_contain: bytes) -> bytes:
@@ -99,53 +99,6 @@ async def test_concurrent_read(server, backend):
         await stream.close()
 
 
-async def test_fork(backend):
-    backend = lookup_backend(backend)
-    ok_counter = 0
-
-    async def ok(delay: int) -> None:
-        nonlocal ok_counter
-        await sleep(backend, delay)
-        ok_counter += 1
-
-    async def fail(message: str, delay: int) -> None:
-        await sleep(backend, delay)
-        raise RuntimeError(message)
-
-    await backend.fork(ok, [0], ok, [0])
-    assert ok_counter == 2
-
-    with pytest.raises(RuntimeError, match="Oops"):
-        await backend.fork(ok, [0], fail, ["Oops", 0.01])
-
-    assert ok_counter == 3
-
-    with pytest.raises(RuntimeError, match="Oops"):
-        await backend.fork(ok, [0.01], fail, ["Oops", 0])
-
-    assert ok_counter == 3
-
-    with pytest.raises(RuntimeError, match="Oops"):
-        await backend.fork(fail, ["Oops", 0.01], ok, [0])
-
-    assert ok_counter == 4
-
-    with pytest.raises(RuntimeError, match="Oops"):
-        await backend.fork(fail, ["Oops", 0], ok, [0.01])
-
-    assert ok_counter == 4
-
-    with pytest.raises(RuntimeError, match="My bad"):
-        await backend.fork(fail, ["My bad", 0], fail, ["Oops", 0.01])
-
-    with pytest.raises(RuntimeError, match="Oops"):
-        await backend.fork(fail, ["My bad", 0.01], fail, ["Oops", 0])
-
-    # No 'match', since we can't know which will be raised first.
-    with pytest.raises(RuntimeError):
-        await backend.fork(fail, ["My bad", 0], fail, ["Oops", 0])
-
-
 def test_lookup_backend():
     assert isinstance(lookup_backend("asyncio"), AsyncioBackend)
     assert isinstance(lookup_backend("trio"), TrioBackend)