Hi Glyph,

Yes.  However, if you were to consider something like
>
> for each in range(10):
>     writer.write(b"A")
>     yield from writer.drain() # be polite! don't buffer too much at once!
>
>
> you might reasonably expect, reasoning about this coroutine by itself, 
> that you will see a string of 10 "A"s on the wire. 
>

No. Reasoning about that very coroutine one immediately asks: what's that 
yield from doing there? This is actually
a very good example why this way of programming is a good idea: bugs become 
so obvious. The rule is so
simple: don't put yield froms into code that should execute as one block. 
Those yield froms even need to be
explicitly there, they cannot be hidden in a subroutine.

Sure, there are situations in which such a programming technique is not a 
good idea, but this also becomes
evident very quickly: if you realize that you do need yield froms between 
your writes (for whatever reason)
then it's a good idea to change strategy. 


> It's theoretically solvable, but for social reasons this is still not 
> something that you want to encourage.  Once you start having a fair 
> queueing system around drain() it raises the question of having a fair 
> queueing system for writing whole *large* messages, which means you then 
> need some kind of higher level lock on the stream, which becomes very 
> confusing (every stream becomes its own full-fledged task scheduler).
>
 
Only because some applications might need a complicated scheduler does not 
mean everyone needs it.
Compare that to the task scheduler of asyncio: it's very basic. And that's 
fine, as it is good enough for
the vast majority of applications. And those who need something better, are 
free to implement their improved
scheduler.

If your argument was true, this would mean that also the asyncio scheduler 
would need to be a full-fledged
fair scheduler, just because some appplications need it.

Anyhow, I'll write my small FIFO output scheduler, it will do the job for 
my small project, so I don't care
anymore whether StreamWriter.drain works task-concurrently or not.

Greetings

Martin

Reply via email to