Advertisement
Guest User

Untitled

a guest
May 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. import multiprocessing
  2. import time
  3.  
  4.  
  5. def f(x):
  6. print("starting")
  7. time.sleep(3)
  8. print("ending")
  9. return 1
  10.  
  11.  
  12. def g(x):
  13. raise Exception("hoge")
  14.  
  15.  
  16. if __name__ == "__main__":
  17. multiprocessing.freeze_support()
  18.  
  19. with multiprocessing.Pool(processes=1) as pool:
  20. res = pool.apply_async(f, (2,))
  21. print(res.get(timeout=4))
  22.  
  23. res = pool.apply_async(g, (2,))
  24. print(res.get(timeout=1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement