Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. # Execute $(1) with each entry of $(2) as variable "arg" in parallel, $(3) seconds timeout
  2. # ex $(call _parallel,some_parallel_task $$arg,apple pear orange,10)
  3. # will execute
  4. # some_parallel_task apple
  5. # some_parallel_task pear
  6. # some_parallel_task orange
  7. # in parallel each with a timeout for 10 seconds, and await completion
  8. define _parallel
  9. @rm -rf .parallel.pids
  10. @$(foreach arg,$(2), \
  11. arg=$(arg); \
  12. timeout $(3)s $(1) & \
  13. echo $$! >> .parallel.pids; \
  14. ) \
  15. while read pid; do \
  16. wait $$pid; \
  17. done <.parallel.pids
  18. @rm -rf .parallel.pids
  19. endef
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement