Reputation: 6339
I'm trying to optimise an expensive operation in some existing code using parallel processing. I've used concurrent.futures
to do so in the past but only when they didn’t return anything.
This time I want to marshall the results, but when printing my collection I'm getting every future's status as something like <Future at 0x... state=finished raised TypeError>
. Can anyone explain what I'm doing wrong?
import concurrent.futures
with concurrent.futures.ProcessPoolExecutor() as executor:
def _future(self) -> None:
print("here")
futures = []
for number in list(range(0,100)):
future = executor.submit(_future)
futures.append(future)
finished = concurrent.futures.wait(futures, 5)
print(finished)
Upvotes: 11
Views: 19328
Reputation: 107134
Your _future
function takes one parameter, and yet your executor.submit
is passing no argument to it. You should pass, for example, number
, as an argument to it instead:
for number in list(range(0,100)):
future = executor.submit(_future, number)
futures.append(future)
On the other hand, since you're naming _future
's one parameter as self
, it implies you intend it to be an instance of a class, in which case you should pass to it the proper instance object in your original, non-minimized code.
Upvotes: 13