Skip to content Skip to sidebar Skip to footer

Multi-tasking With Multiprocessing Or Threading Or Asyncio, Depending On The Scenario

I have my codes ready for 1 at a time performance, I wanna upgrade it to something fancy, multi-tasking. I am seeking helps about what I can use to achieve my goal. my codes perfo

Solution 1:

So off the top of my head you can look at 2 things.

1) Asyncio (be careful this example uses threading and is not thread safe specifically the function asyncio.gather)

import asyncio
for work in [1,2,3,4,5]:
    tasks.append(method_to_be_called(work))

results = await asyncio.gather(*tasks)

2) Asyncio + multiprocessing https://github.com/jreese/aiomultiprocess


Post a Comment for "Multi-tasking With Multiprocessing Or Threading Or Asyncio, Depending On The Scenario"