On 2015-09-03 1:11 PM, Guido van Rossum wrote:
I agree (unsurprisingly since it seems I brought it up in the first place :-). I wonder if the parameter name should be other than timeout, since it may surprise people that a readline() with a timeout of 5 secs can take longer than 5 secs to complete. But I have no good suggestion for a better name, unless you like low_level_timeout.

I also wonder if it would make sense to set the timeout as part of the stream state rather than passing it on every call? (The API gets so noisy when all methods have this extra parameter.

Can we have one default timeout for all StreamReader methods, and keyword argument 'timeout' for read(), readexactly() and readline() to override it?

   StreamReader.set_timeout()
   StreamReader.get_timeout()
   StreamReader.read(n=-1, timeout=None)
   StreamReader.readline(timeout=None)
   StreamReader.readexactly(n, timeout=None)

This way it will be possible to configure StreamReader with a default safe timeout when a protocol is created, and then further customize timeouts depending on what you're doing (like reading an HTTP header line should be quicker than receiving a huge chunk of data).

Also, with StreamReader implementing asynchronous iteration protocol in 3.5, it might be useful to have a default timeout to safely iterate through lines:

   reader.set_timeout(1)
   async for line in reader:
       ...

Yury

Reply via email to