Timeout whilst getting response's body
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 603
- Forks
- 140
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I've started using treq on unstable network and I realized that there is no way to define timeout while getting response content. So sometimes I can't process request as it is hanged.
My idea to solve that is to pass request_kwargs to _Response and _BufferedResponse and collect function should look like:
def collect(response, request_kwargs, collector):
"""
Incrementally collect the body of the response.
This function may only be called **once** for a given response.
:param IResponse response: The HTTP response to collect the body from.
:param collector: A callable to be called each time data is available
from the response body.
:type collector: single argument callable
:rtype: Deferred that fires with None when the entire body has been read.
"""
if response.length == 0:
return succeed(None)
d = Deferred()
response.deliverBody(_BodyCollector(d, collector))
if request_kwargs.get('timeout'):
delayedCall = default_reactor(request_kwargs.get('reactor')).callLater(
request_kwargs.get('timeout'), d.cancel)
def gotResult(result):
if delayedCall.active():
delayedCall.cancel()
return result
d.addBoth(gotResult)
return d
Guys, can you confirm that issue makes sense?
If yes, I'll prepare more proper fix with tests.
Cheers!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading _Response, _BufferedResponse, and collect, then trace how request_kwargs and the reactor are passed into response-body handling. Confirm the timeout behavior around _BodyCollector and identify the existing test layout before adding coverage. Done means response collection can honor the request timeout and the timeout is cleaned up when collection finishes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100