SHARE
TWEET

Untitled

a guest May 16th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top