Issue
I'm using asyncio (in python 3.6) to schedule multiple asynchronous tasks.
On the following example:
import concurrent.futures
import time
import asyncio
def long_task(t):
print(t)
time.sleep(1)
return t
loop = asyncio.get_event_loop()
executor = concurrent.futures.ThreadPoolExecutor(max_workers=3)
inputs = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
futures = [loop.run_in_executor(executor, long_task, i) for i in inputs]
Is there a way to get the number of finished tasks ?
Thanks
Solution
I found something, asyncio Future object have a done() function:
from asyncio import Future
from typing import List
def get_progress(futures: List[Future]) -> int:
return sum([f.done() for f in futures])
Answered By - RobinFrcd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.