classification
Title: http.client doesn't close. Infinite loop
Type: behavior Stage: patch review
Components: Documentation Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, martin.panter, skorpeo
Priority: normal Keywords: patch, patch, patch, patch

Created on 2019-01-03 16:41 by skorpeo, last changed 2019-01-06 01:09 by python-dev.

Pull Requests
URL Status Linked Edit
PR 11441 open python-dev, 2019-01-06 01:09
PR 11441 open python-dev, 2019-01-06 01:09
PR 11441 python-dev, 2019-01-06 01:09
PR 11441 open python-dev, 2019-01-06 01:09
Messages (3)
msg332934 - (view) Author: (skorpeo) Date: 2019-01-03 16:41
when testing example from https://docs.python.org/3/library/http.client.html.  Specifically the chunked example, i.e. while not r1.closed.  Results in infinite loop.  

I believe this is because line 398 function def _close_conn(self), should call self.close().
msg332947 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2019-01-03 20:21
This was changed in Python 3.2+ in Issue 16723. The response object no longer sets the “closed” attribute when it runs out of data; it is only set when the “close” method is called. Perhaps the example should be amended so that it checks if “read” returned an empty string, rather than checking “closed”.

Another problem with the example is that printing the chunk as a bytes object can trigger BytesWarning. I would add a “repr” call to avoid that.
msg332950 - (view) Author: (skorpeo) Date: 2019-01-03 22:07
Ha, ok that would explain it.  Yes, I think it would indeed be helpful to
update the example, but then again I guess leaving it as is may be a good
way to find out if people are reading the docs.

On Thu, Jan 3, 2019 at 10:21 PM Martin Panter <report@bugs.python.org>
wrote:

>
> Martin Panter <vadmium+py@gmail.com> added the comment:
>
> This was changed in Python 3.2+ in Issue 16723. The response object no
> longer sets the “closed” attribute when it runs out of data; it is only set
> when the “close” method is called. Perhaps the example should be amended so
> that it checks if “read” returned an empty string, rather than checking
> “closed”.
>
> Another problem with the example is that printing the chunk as a bytes
> object can trigger BytesWarning. I would add a “repr” call to avoid that.
>
> ----------
> assignee:  -> docs@python
> components: +Documentation
> nosy: +docs@python, martin.panter
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue35649>
> _______________________________________
>
History
Date User Action Args
2019-01-06 01:09:48python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request10886
2019-01-06 01:09:41python-devsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request10887
2019-01-06 01:09:34python-devsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request10885
2019-01-06 01:09:28python-devsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request10884
2019-01-04 21:32:55terry.reedysetversions: + Python 3.8, - Python 3.5, Python 3.6
2019-01-03 22:07:33skorpeosetmessages: + msg332950
title: http.client doesn't close. Infinite loop -> http.client doesn't close. Infinite loop
2019-01-03 20:21:41martin.pantersetnosy: + docs@python, martin.panter
messages: + msg332947

assignee: docs@python
components: + Documentation
2019-01-03 16:45:41skorpeosettype: behavior
2019-01-03 16:41:48skorpeocreate