Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for the first finished parallel proccess #1546

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions metaflow/multicore_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from itertools import islice
from multiprocessing import cpu_count
from tempfile import NamedTemporaryFile
import time

try:
# Python 2
Expand Down Expand Up @@ -68,8 +69,17 @@ def parallel_imap_unordered(func, iterable, max_parallel=None, dir=None):

while pids:

pid, output_file = pids.pop()
if os.waitpid(pid, 0)[1]:
for idx, pid_info in enumerate(pids):
pid, output_file = pid_info
pid, exit_code = os.waitpid(pid, os.WNOHANG)
if pid:
pids.pop(idx)
break
else:
time.sleep(1) # Wait a bit before re-checking
maxzheng marked this conversation as resolved.
Show resolved Hide resolved
continue

if exit_code:
raise MulticoreException("Child failed")

with open(output_file, "rb") as f:
Expand Down
12 changes: 12 additions & 0 deletions test/unit/test_multicore_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from metaflow.multicore_utils import parallel_map


def test_parallel_map():
assert parallel_map(lambda s: s.upper(), ["a", "b", "c", "d", "e", "f"]) == [
"A",
"B",
"C",
"D",
"E",
"F",
]