Last active
November 7, 2022 16:16
-
-
Save cpelley/da3f3f43e2b3fb2288a78dd659d1d59a to your computer and use it in GitHub Desktop.
Testing gnu parallel behaviour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import sys | |
| from time import sleep | |
| import random | |
| for i in range(random.randint(3, 8)): | |
| sleep(random.random() / 10) | |
| print(f"{sys.argv[1]}, step {i}") | |
| if i == 2 and ("arg1" in sys.argv[1] or "arg2" in sys.argv[1]): | |
| raise ValueError(f"{sys.argv[1]} raised an exception") |
Author
Author
We can retain our error code AND still echo our 'endgroup' with a minor change:
$ parallel 'echo ::group::{}; ./random_duration_script.py {} && echo ::endgroup:: || (echo ::endgroup:: && exit 1) ' ::: arg1 arg2 arg3 arg4 arg5 2&> /dev/null; echo $?
2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Removing the commands wrapping the call to
random_duration_script.pyconfirms that the error code is otherwise preserved even when processes complete successfully following a failing process:(note that I pipe stdout and stderr to /dev/null here as it is unimportant in this exploration of error code handling of 'parallel')