From: Tom Christie Date: Tue, 25 Jun 2019 12:24:12 +0000 (+0100) Subject: Version 0.6.4 (#105) X-Git-Tag: 0.6.4^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5326cd1a20a5264afe5b1b89178d0a7feb23ccb7;p=thirdparty%2Fhttpx.git Version 0.6.4 (#105) * Read/Write timeout modes * Read/Write timeout modes * Tweaks for read/write timeout modes * Version 0.6.4 * Make slow_response slower for timeout test --- diff --git a/http3/__init__.py b/http3/__init__.py index 3be34560..306af81c 100644 --- a/http3/__init__.py +++ b/http3/__init__.py @@ -49,4 +49,4 @@ from .models import ( ) from .status_codes import StatusCode, codes -__version__ = "0.6.3" +__version__ = "0.6.4" diff --git a/http3/concurrency.py b/http3/concurrency.py index bd04c2da..928efcfe 100644 --- a/http3/concurrency.py +++ b/http3/concurrency.py @@ -95,15 +95,16 @@ class Reader(BaseReader): timeout = self.timeout while True: + # Check our flag at the first possible moment, and use a fine + # grained retry loop if we're not yet in read-timeout mode. should_raise = flag is None or flag.raise_on_read_timeout + read_timeout = timeout.read_timeout if should_raise else 0.01 try: - data = await asyncio.wait_for( - self.stream_reader.read(n), timeout.read_timeout - ) + data = await asyncio.wait_for(self.stream_reader.read(n), read_timeout) break except asyncio.TimeoutError: if should_raise: - raise ReadTimeout() + raise ReadTimeout() from None return data @@ -133,9 +134,12 @@ class Writer(BaseWriter): ) break except asyncio.TimeoutError: + # We check our flag at the possible moment, in order to + # allow us to suppress write timeouts, if we've since + # switched over to read-timeout mode. should_raise = flag is None or flag.raise_on_write_timeout if should_raise: - raise WriteTimeout() + raise WriteTimeout() from None async def close(self) -> None: self.stream_writer.close() diff --git a/tests/conftest.py b/tests/conftest.py index 1d209517..92b05832 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,7 +30,7 @@ async def hello_world(scope, receive, send): async def slow_response(scope, receive, send): - await asyncio.sleep(0.01) + await asyncio.sleep(0.1) await send( { "type": "http.response.start",