I am using requests to download a large (~50MiB) file on a small embedded device running Linux.
File is to be written to attached MMC.
Unfortunately MMC write speed is lower then net speed and I see memory consumption raise and, in a few cases I even had kernel "unable to handle page..." error.
Device has only 128MiB RAM.
The code I'm using is:
with requests.get(URL, stream=True) as r:
if r.status_code != 200:
log.error(f'??? download returned {r.status_code}')
return -(offset + r.status_code)
siz = 0
with open(sfn, 'wb') as fo:
for chunk in r.iter_content(chunk_size=4096):
fo.write(chunk)
siz += len(chunk)
return siz
How can I temporarily stop server while I writer to MMC?