Skip to content

Instantly share code, notes, and snippets.

@mcwitt
Created August 10, 2022 15:27
Show Gist options
  • Save mcwitt/61375760cd5ba32415c5bceeec008214 to your computer and use it in GitHub Desktop.
Save mcwitt/61375760cd5ba32415c5bceeec008214 to your computer and use it in GitHub Desktop.
import traceback
from concurrent import futures
executor = futures.ProcessPoolExecutor(2)
def raise_if_42(n: int):
if n == 42:
raise Exception("got scary number")
return n
should_raise = executor.submit(raise_if_42, 42)
should_succeed = executor.submit(raise_if_42, 1)
print(should_succeed.result())
try:
print(should_raise.result())
except:
print("Failed with the following exception")
traceback.print_exc()
print("Recovered")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment