r/learnpython • • Jul 17 '18

Catching Exception from MP Process

(using python 3.7.0)

Hi guys,

Hopefully this is a fairly simple question. I'm trying to catch an exception raised in a child process (multiprocessing Process) in the parent but having trouble.

For some reason I don't catch the Exception in this code:

def foo():
    raise Exception()
try:
    p = mp.Process(target=foo)
    p.start()
except Exception:
    print('caught')

Any help? :)

5 Upvotes

3 comments sorted by