Skip to content

Commit

Permalink
Use concurrent.futures.ProcessPoolExecutor to handle better cases w…
Browse files Browse the repository at this point in the history
…here a sub-process crashes.

References python/cpython#66587
  • Loading branch information
KelSolaar committed Jul 28, 2024
1 parent 136e132 commit 91b88de
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions colour/utilities/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from __future__ import annotations

import concurrent.futures
import multiprocessing
import os
import threading

Expand Down Expand Up @@ -2295,16 +2294,19 @@ def process(self) -> None:

self.log(f'Processing "{node}" node...')

with multiprocessing.Pool(processes=self.get_input("processes")) as pool:
results = dict(
pool.map(
self.get_input("task"),
[
(i, element, node, self)
for i, element in enumerate(self.get_input("array"))
],
)
)
results = {}
with concurrent.futures.ProcessPoolExecutor(
max_workers=self.get_input("processes")
) as executor:
futures = [
executor.submit(self.get_input("task"), (i, element, node, self))
for i, element in enumerate(self.get_input("array"))
]

for future in concurrent.futures.as_completed(futures):
index, element = future.result()
self.log(f'Processed "{element}" element with index "{index}".')
results[index] = element

results = dict(sorted(results.items()))
self.set_output("results", list(results.values()))
Expand Down

0 comments on commit 91b88de

Please sign in to comment.