Thread pool task deadlock
Review this Python parallel tree-aggregator using a thread pool.
Under a deep/wide tree this hangs. What is the concurrency bug?
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 40 min
Mark a line and say what kind of problem it is.0 findings
1from concurrent.futures import ThreadPoolExecutor
2
3pool = ThreadPoolExecutor(max_workers=4)
4
5def aggregate(node):
6 if node.is_leaf:
7 return node.value
8 # fan each child out to the pool, then block on the results
9 futures = [pool.submit(aggregate, c) for c in node.children] # (1)
10 return sum(f.result() for f in futures) # (2)
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.