I am trying to set custom sys.excepthook
on multiprocess.
but it does not work.
In below code, I have expected that to print This is my traceback function:
string as a prefix of error message, but it doesn't.
code:
from multiprocessing import Process
import time
import traceback
import logging
import sys
def excepthook(etype, evalue, traceback):
traceback_strs = traceback.format_exception_only(etype, evalue)
exception_str = "This is my traceback function:" + "\r\n".join(traceback_strs)
print("ExceptHook")
print(exception_str)
def subprocess_main():
sys.excepthook = excepthook
time.sleep(3)
raise Exception("HelloWorld")
if __name__ == "__main__":
p = Process(target=subprocess_main)
p.start()
p.join()
Why it does not work?
OS:Windows10
Python: 3.6.3