multiprocessing: excepthook not getting called
Philipp Hagemeister
phihag at phihag.de
Wed Jun 13 04:40:01 EDT 2012
multiprocessing just mimicks the threading module here, see
http://bugs.python.org/issue1230540 . Why do you need excepthook in the
first place?
You can perfectly simulate it by wrapping the root method (target in
your example) in a try .. catch:
import multiprocessing
import sys
def printErrors(func):
def wrapped(*args, **kwargs):
try:
func()
except:
print ('except: ', sys.exc_info())
return wrapped
@printErrors
def target():
raise ValueError()
if __name__ == '__main__':
p = multiprocessing.Process(target=target)
p.start()
p.join()
# try it here in main
target()
Cheers,
Philipp
On 06/12/2012 11:02 PM, Dave Cook wrote:
> Why doesn't my excepthook get called in the child process?
>
> import sys
> import multiprocessing as mp
>
> def target():
> name = mp.current_process().name
> def exceptHook(*args):
> print 'exceptHook:', name, args
> sys.excepthook = exceptHook
> raise ValueError
>
> if __name__=='__main__':
> p = mp.Process(target=target)
> p.start()
> p.join()
> # try it here in main
> target()
>
> Thanks,
> Dave Cook
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20120613/c157362d/attachment.sig>
More information about the Python-list
mailing list