Skip to content

Instantly share code, notes, and snippets.

@cpelley
Last active November 7, 2022 16:16
Show Gist options
  • Select an option

  • Save cpelley/da3f3f43e2b3fb2288a78dd659d1d59a to your computer and use it in GitHub Desktop.

Select an option

Save cpelley/da3f3f43e2b3fb2288a78dd659d1d59a to your computer and use it in GitHub Desktop.
Testing gnu parallel behaviour
#!/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")
@cpelley
Copy link
Author

cpelley commented Nov 7, 2022

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