Ich versuche, benutzerdefinierte sys.excepthook
auf Multiprocess festzulegen. aber es funktioniert nicht.Python sys.excepthook auf multiprocess
Im unteren Code habe ich erwartet, dass This is my traceback function:
Zeichenfolge als Präfix der Fehlermeldung gedruckt wird, aber es nicht.
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()
Warum es nicht funktioniert?
OS: Microsoft Windows 10
Python: 3.6.3