classification
Title: asyncio: add timeout to StreamReader read methods
Type: Stage: resolved
Components: asyncio Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, thehesiod, vstinner, yselivanov
Priority: normal Keywords: patch

Created on 2015-01-14 00:48 by vstinner, last changed 2018-09-19 23:32 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
streamreader_timeout.patch vstinner, 2015-01-14 00:48 review
Messages (4)
msg233978 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-14 00:48
Attached patch adds an optional timeout parameter to the read(), read_exactly() and readline() methods of StreamReader.

If a single read takes longer than timeout seconds, a asyncio.TimeoutError is raised. The timeout is reset each time new data is received.

Read data is pushed back to the StreamReader buffer if the wait raises an exception (timeout, cancelled, etc.), so it's possible to retry the read later.
msg233979 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-14 00:49
Copy of the feature requets by Guido van Rossum:
https://code.google.com/p/tulip/issues/detail?id=96

Often you want to stop servicing (or using) a connection when there is no activity in a given time.  You can do this by wrapping all your read calls in wait_for(), but a single readline() or readexactly() call may do multiple I/O operations and typically you want to reset the timeout whenever you receive some more bytes.  So it makes more sense to either add the timeout to the various read*() calls, or even to (optionally) set it in the constructor, so that the class can implement a more subtle timeout algorithm.

I could imagine an overall timeout too, and possibly even something that gives up if the bandwidth goes below a threshold, to avoid waiting forever on a huge download.

(For StreamWriter I think it's sufficient to call wait_for(w.drain()), so I think this only applies to StreamReader.)
msg263864 - (view) Author: Alexander Mohr (thehesiod) * Date: 2016-04-20 23:45
any updates on this?  I think this would be perfect for https://github.com/aio-libs/aiobotocore/issues/31
msg325830 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-09-19 23:32
This feature request doesn't seem popular and I lost track of it, so I just close the issue. Sorry.
History
Date User Action Args
2018-09-19 23:32:14vstinnersetstatus: open -> closed
resolution: out of date
messages: + msg325830

stage: resolved
2016-04-20 23:45:50thehesiodsetnosy: + thehesiod
messages: + msg263864
2015-01-14 00:49:35vstinnersetmessages: + msg233979
2015-01-14 00:48:28vstinnercreate