Hi, got a question about thread pool concurrency. I have a challenging problem, where I have the code:
from concurrent.futures import ThreadPoolExecutor
import time
N_THREADS = 12
pool = ThreadPoolExecutor(max_workers=N_THREADS)
def JobA():
def work():
time.sleep(5)
return 1
return pool.submit(work)
def JobB(intermediate):
def work():
time.sleep(3)
return intermediate * 2
return pool.submit(work)
def JobC():
def work():
time.sleep(4)
return 1
return pool.submit(work)
def job():
r1 = JobA()
r2 = JobB(r1)
r3 = JobC()
return r1 + r2 + r3
This can be thought as a dependency graph:
A -> B -\
-> RESULT
C -/
How do I keep the syntax similar to what is seen in the function job while optimizing the usage of the thread pool?