Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. '''
  4. MOVED FROM /orions4-zfs/projects/rqi/Code/3dcnn/lfd/run_parallel.py
  5. PLEASE CHECK ORIGINAL FILE FOR UPDATES!
  6. '''
  7.  
  8. import os
  9. import sys
  10. import datetime
  11. from functools import partial
  12. from multiprocessing.dummy import Pool
  13. from subprocess import call
  14.  
  15. '''
  16. @brief:
  17. run commands in parallel
  18. @usage:
  19. python run_parallel.py command_list.txt
  20. where each line of command_list.txt is a executable command
  21. '''
  22. command_file = sys.argv[1]
  23. commands = [line.rstrip() for line in open(command_file)]
  24.  
  25. report_step = 10
  26. pool = Pool(10)
  27.  
  28. for idx, return_code in enumerate(pool.imap(partial(call, shell=True), commands)):
  29. if idx % report_step == 0:
  30. print('[%s] command %d of %d' % (datetime.datetime.now().time(), idx, len(commands)))
  31. if return_code != 0:
  32. print('!! command %d of %d (\"%s\") failed' % (idx, len(commands), commands[idx]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement