Skip to content

send_file with > 500kb ends with MemoryError: memory allocation failed, allocating 1025 bytes #121

Answered by miguelgrinberg
Micha10 asked this question in Q&A
Discussion options

You must be logged in to vote

It cannot be a problem with file size, because as you've discovered, files are sent in fixed-size chunks. But if you get a few concurrent requests I guess it is possible that you are running out of memory.

Can you try adding this at the top of your server file?

from microdot_asyncio import Response
Response.send_file_buffer_size = 256

The default is 1024 bytes for each file chunk. Hopefully you can find a size that allows all your static file requests to go through. Unfortunately the server can still blow up if two clients connect at the same time though.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Micha10
Comment options

Answer selected by Micha10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants