Skip to content

Instantly share code, notes, and snippets.

@ashiato45
Created May 6, 2019 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashiato45/0b5f32e5d6a9fb22888e29b7baceb0cf to your computer and use it in GitHub Desktop.
Save ashiato45/0b5f32e5d6a9fb22888e29b7baceb0cf to your computer and use it in GitHub Desktop.
import multiprocessing
import time
def f(x):
print("starting")
time.sleep(3)
print("ending")
return 1
def g(x):
raise Exception("hoge")
if __name__ == "__main__":
multiprocessing.freeze_support()
with multiprocessing.Pool(processes=1) as pool:
res = pool.apply_async(f, (2,))
print(res.get(timeout=4))
res = pool.apply_async(g, (2,))
print(res.get(timeout=1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment