Created
July 29, 2022 07:48
-
-
Save larsyencken/3821a0c9eaffd5170b7c62c03dec4170 to your computer and use it in GitHub Desktop.
Python: isolate a function in a separate process
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
from concurrent.futures import ProcessPoolExecutor | |
def dog(): | |
raise ValueError('not a dog, a cat') | |
def main(): | |
try: | |
with ProcessPoolExecutor(1) as executor: | |
executor.submit(dog).result() | |
print('no exception') | |
except ValueError: | |
print('got the exception!') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment