How to get grand child process' Exception without modifying child process

I’m developing a platform that help users run their code. The typical workflow would be:
my process --subprocess.Popen–> user control process --subprocess/mutiprocessing–> user working processes

Is there any way to catch unhandled Exception generated by both user control process and user working processes without modifying them?
I know how to catch only user control process’s unhandled Exception like: Python sys.excepthook on multiprocess - Stack Overflow
Yet, I have no idea about how to catch user working processes’s in the workflow.

Maybe you can set PYTHONSTARTUP to inject some code into the python process to start in the child?

1 Like

PYTHONSTARTUP only works with interactive mode. Is there any equivalent mechanism for script mode?

sitecustomize can do the job.