Issue
I have a function that submits several tasks to a ThreadPoolExecutor
and return a list of Futures created by each submission:
def submit_tasks() -> [Future]:
futures = []
for i in range(10):
future = executor.submit(Task())
futures.append(future)
return futures
def submit() -> Future:
futures = submit_tasks()
# I would like this function to return a single Future that clients can use to check
# whether all futures in the list have completed. How to do that?
I'm on Python 3.8
I would like this function to return a single Future that clients can use to check whether all futures in the list have completed. How to do that?
Solution
Use concurrent.futures.wait
: https://docs.python.org/3/library/concurrent.futures.html#module-functions
from concurrent.futures import Future, wait
...
def submit() -> Future:
return wait(submit_tasks())
Answered By - Samwise
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.