Last active
September 5, 2020 13:16
-
-
Save im-noob/7699a2b0ec0ef65ea3ce53a7781b6ac6 to your computer and use it in GitHub Desktop.
asyncio python Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import nest_asyncio | |
nest_asyncio.apply() | |
async def task(batch_no,roll_no): | |
return batch_no,roll_no | |
async def batch_creator(batch_no): | |
result = [] | |
for roll_no in range(BATCH_SIZE): | |
result.append(loop.create_task(task(batch_no,roll_no))) | |
return result | |
async def resCollector(): | |
for batch_no in range(BATCH_COUNT): | |
for m in await batch_creator(batch_no): | |
output = await m | |
with open('output.txt','a') as f: | |
f.write(str(output)+'\n') | |
loop = asyncio.get_event_loop() | |
final = asyncio.run(resCollector()) | |
print('Finish Execution') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment