I am starting with asyncio that I wish to apply to following problem:
- Data is split in chunks.
- A chunk is 1st compressed.
- Then the compressed chunk is written in the file.
- A single file is used for all chunks, so I need to process them one by one.
with open('my_file', 'w+b') as f:
for chunk in chunks:
compress_chunk(ch)
f.write(ch)
From this context, to run this process faster, as soon as the write
step of current iteration starts, could the compress
step of next iteration be triggered as well?
Can I do that with asyncio
, keeping a similar for
loop structure? If yes, could you share some pointers about this?
I am guessing another way to run this in parallel is by using ProcessPoolExecutor
and splitting fully the compress
phase from the write
phase. This means compressing 1st all chunks in different executors.
Only when all chunks are compressed, then starting the writing step .
But I would like to investigate the 1st approach with asyncio
1st, if it makes sense.
Thanks in advance for any help. Bests