Raising exception during ExecutePythonScript does not change exit code of the editor

When we encounter an exception in Python code run with ExecutePythonScript, it stops the Python execution, and then the editor closes with exit code 0. So, when we run on a remote farm, the job seems like it completes successfully because there is no indication that the editor process errored. Is there a way to propagate the Python error so that the editor knows something bad happened and our farm software can say the job failed?

Steps to Reproduce
Run Python code with ExecutePythonScript, and raise an exception. See that the editor closes with exit code 0.

Hi Chad,

To do that, I believe you need to set an exception hook in Python itself:

`import sys
import traceback
import unreal

def excepthook(exc_type, exc_value, exc_traceback):
print(“=== Unhandled Python Exception! ===”)
traceback.print_exception(exc_type, exc_value, exc_traceback)
unreal.MyBlueprintFunctionLibrary.request_exit_with_status(123)

sys.excepthook = excepthook`Further down the code, if a runtime exception happens, the code inside the hook should run. To force the engine to quit with a status code, though, you will need to call a function that is not exported to Python by default. You can easily export it, for example, within a blueprint function library:

void UMyBlueprintFunctionLibrary::RequestExitWithStatus(int code) { FPlatformMisc::RequestExitWithStatus(true, code); }Please let me know if this solution works for you.

Best regards,

Vitor

That works great. Thanks!