Guest User

Untitled

a guest
Jul 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. def services():
  2. services = [method1(),
  3. method2(),
  4. method3(),
  5. mrthod4(),
  6. method5()]
  7. return services
  8.  
  9. def runAll():
  10. import subprocess
  11. for i in services():
  12. proc = subprocess.call(i,shell=True)
  13.  
  14. from joblib import Parallel, delayed
  15.  
  16. functions = [fn1, fn2, fn3, fn4]
  17.  
  18. results = Parallel(n_jobs=4)(delayed(f)() for f in functions)
  19.  
  20. subprocess.call("./foo1&", shell=True)
  21. subprocess.call("./foo2&", shell=True)
  22.  
  23. from multiprocessing import Process
  24.  
  25. def f1():
  26. while True:
  27. print 'foo'
  28.  
  29. def f2():
  30. while True:
  31. print 'bar'
  32.  
  33. def f3():
  34. while True:
  35. print 'baz'
  36.  
  37. if __name__ == '__main__':
  38. for func in (f1, f2, f3):
  39. Process(target=func).start()
  40.  
  41. from multiprocessing import Pool
  42. def parallelfuncs(funcs, args, results, bad_value = None):
  43. p = Pool()
  44. waiters = []
  45. for f in funcs:
  46. waiters.append(p.apply_async(f, args, callback = results.append))
  47. p.close()
  48. for w in waiters:
  49. if w.get()[0] == bad_value:
  50. p.terminate()
  51. return p
  52.  
  53. results = []
  54. parallelfuncs(services, args, results).join()
  55. print results
Add Comment
Please, Sign In to add comment