Skip to content

Instantly share code, notes, and snippets.

@larsyencken
Created July 29, 2022 07:48
Show Gist options
  • Save larsyencken/3821a0c9eaffd5170b7c62c03dec4170 to your computer and use it in GitHub Desktop.
Save larsyencken/3821a0c9eaffd5170b7c62c03dec4170 to your computer and use it in GitHub Desktop.
Python: isolate a function in a separate process
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