Fun with IO

Frank Millman frank at chagford.com
Wed Jan 22 01:00:22 EST 2020


On 2020-01-21 6:17 PM, Maxime S wrote:
> Hi,
> 
> Le ven. 17 janv. 2020 à 20:11, Frank Millman <frank at chagford.com> a écrit :
> 
> 
>> It works perfectly. However, some pdf's can be large, and there could be
>> concurrent requests, so I wanted to minimise the memory footprint. So I
>> tried passing the client_writer directly to the handler -
>>
>>       await pdf_handler(client_writer)
>>       client_writer.write(b'\r\n')
>>
>> It works! ReportLab accepts client_writer as a file-like object, and
>> writes to it directly. I cannot use chunking, so I just let it do its
>> thing.
>>
>> Can anyone see any problem with this?
>>
>>
> If the socket is slower than the PDF generation (which is probably always
> the case, unless you have a very fast network), it will still have to be
> buffered in memory (in this case in the writer buffer). Since writer.write
> is non-blocking but is not a coroutine, it has to buffer. There is an
> interesting blog post about that here that I recommend reading:
> https://lucumr.pocoo.org/2020/1/1/async-pressure/
> 

Thanks for the comments and for the link - very interesting.

Following the link led me to another essay -

https://github.com/guevara/read-it-later/issues/4558

I only understood a portion of it, but it forces you to question your 
assumptions, which is always a good thing.

Frank


More information about the Python-list mailing list