Skip to content

Commit bc1ec63

Browse files
committed
ENH: Untangle fd 1 and 2 contents of parallel children
1 parent 48c29db commit bc1ec63

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

myba.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,23 @@ _parallelize () {
309309
fi
310310
# Call function with args and variables in background
311311
# shellcheck disable=SC2016,SC2294
312-
{ eval "$@" $(seq -s' ' -f '"$var%.0f"' "$n_vars"); } &
312+
{
313+
eval "$@" $(seq -s' ' -f '"$var%.0f"' "$n_vars")
314+
} 1>"$PLAIN_REPO/_fd1" \
315+
2>"$PLAIN_REPO/_fd2" &
313316
pids="$pids $!"
317+
mv "$PLAIN_REPO/_fd1" "$PLAIN_REPO/_fd1_$!"
318+
mv "$PLAIN_REPO/_fd2" "$PLAIN_REPO/_fd2_$!"
314319
done
315320
# Wait on all spawned jobs; transferring their exit status to ours
316-
for pid in $pids; do wait "$pid"; done
321+
status=0
322+
for pid in $pids; do
323+
if ! wait "$pid"; then status=1; fi
324+
cat "$PLAIN_REPO/_fd1_$pid"
325+
cat "$PLAIN_REPO/_fd2_$pid" >&2
326+
done
327+
rm "$PLAIN_REPO"/_fd*_*
328+
if [ $status -ne 0 ]; then exit 1; fi
317329
done
318330
}
319331

0 commit comments

Comments
 (0)