5

I'm trying to use a custom sys.excepthook with the multiprocessing library to handle exceptions on all threads. I know there's an outstanding bug with python that prevents this from working correctly with the Threading library, and testing shows that this also affects multiprocessing.

The Python bug and Stackoverflow post that led me to it both have workarounds for the Threading library, but nothing for multiprocessing. I have tried to adapt the workaround for use with multiprocessing, but the exception is still thrown as usual.

def install_thread_excepthook():
    import sys
    start_old = multiprocessing.Process.start
    def start(*args, **kwargs):
        try:
            start_old(*args, **kwargs)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            sys.excepthook(*sys.exc_info())
    multiprocessing.Process.start = run

How do I make sys.excepthook work properly with multiprocessing?

Community
  • 1
  • 1
Foxocube
  • 710
  • 9
  • 32
  • Does this answer your question? [Python sys.excepthook on multiprocess](https://stackoverflow.com/questions/47815850/python-sys-excepthook-on-multiprocess) – ekuusela Feb 02 '22 at 05:21

0 Answers0