Is there a way to re-send a piece of data for processing, if the original computation failed, using a simple pool?
import random
from multiprocessing import Pool
def f(x):
if random.getrandbits(1):
raise ValueError("Retry this computation")
return x*x
p = Pool(5)
# If one of these f(x) calls fails, retry it with another (or same) process
p.map(f, [1,2,3])
If you can (or don’t mind) retrying immediately, use a decorator wrapping the function: