Created
August 10, 2022 15:27
-
-
Save mcwitt/61375760cd5ba32415c5bceeec008214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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