You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fine-tuning timeouts from the default timeout config #435
Currently, if we want to change only one of the three timeouts (connect, read, write) we need to build a full-blown TimeoutConfig. But there is no way to use the default timeout values.
>>>importhttpx>>>httpx.config.DEFAULT_TIMEOUT_CONFIGTimeoutConfig(timeout=5.0)
>>>httpx.TimeoutConfig(read_timeout=1)
# We'd expect connect_timeout and write_timeout to be 5 (the default)TimeoutConfig(connect_timeout=None, read_timeout=1, write_timeout=None)
Changing TimeoutConfig to automatically use the default values in case some values aren't given is probably not the good way to go, because TimeoutConfig shouldn't contain any smart behavior.
Instead, we should probably allow explicitly building a TimeoutConfig instance from DEFAULT_TIMEOUT_CONFIG:
I'd see it materialize as factory method on TimeoutConfig:
What about making TimeoutConfig(read_timeout=1) result in 5, 1, 5 instead of None, 1, None? Then you have to be explicit about the other two if you truly want "None".
>>># Override one of the timeouts.>>>httpx.TimeoutConfig(read_timeout=1)
TimeoutConfig(connect_timeout=5, read_timeout=1, write_timeout=5)
>>># Disable timeouts.>>>httpx.TimeoutConfig(timeout=None)
TimeoutConfig(connect_timeout=None, read_timeout=None, write_timeout=None)
>>># Set all timeouts to 3 seconds but disable read.>>>httpx.TimeoutConfig(timeout=3, read_timeout=None)
TimeoutConfig(connect_timeout=3, read_timeout=None, write_timeout=3)
This looks like a nice approach to me. I suppose we'd get rid of DEFAULT_TIMEOUT_CONFIG entirely and use TimeoutConfig() instead?
Activity
sethmlarson commentedon Oct 3, 2019
What about making
TimeoutConfig(read_timeout=1)result in 5, 1, 5 instead of None, 1, None? Then you have to be explicit about the other two if you truly want "None".lovelydinosaur commentedon Oct 4, 2019
Simplest question is, what do we want this to return?...
I think we should probably switch things around so that it'll give you
TimeoutConfig(timeout=5)rather thanTimeoutConfig(timeout=None), right?I guess we want something like this...
florimondmanca commentedon Oct 4, 2019
And so we'd have:
This looks like a nice approach to me. I suppose we'd get rid of
DEFAULT_TIMEOUT_CONFIGentirely and useTimeoutConfig()instead?