Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2019-01-08 14:00:18 +0300
committerSybren A. Stüvel <sybren@stuvel.eu>2019-01-08 14:00:18 +0300
commite11bb77f31827f875b536c4dfed18343bcf8f458 (patch)
treeb07920961932f3e88d517872d991a8e2f559c65e /source/creator
parent68b4c57ba5cd231694b0d9b4572a4e1b364f5055 (diff)
Properly clean up Python when exiting due to --python-exit-code
When BPY_python_end() is not called, there can be buffered data still in `sys.stdout` or `sys.stderr`. This generally isn't an issue when those are connected to a terminal, but when they are read by another process (in the case of rendering with Flamenco, for example) we could miss the actual error message that's causing the exit in the first place. The following script demonstrates the issue; before this commit neither the writes to STDERR and STDOUT nor the traceback of the NameError were shown. #!/bin/bash cat > file-with-errors.py <<EOT import sys print('THIS IS STDERR', file=sys.stderr) print('THIS IS STDOUT', file=sys.stdout) nonexisting.monkey = 3 EOT blender --enable-autoexec -noaudio --background \ any-existing-blendfile.blend \ --python-exit-code 42 \ --python file-with-errors.py 2>&1 | cat Reviewers: campbellbarton, mont29 Reviewed By: campbellbarton, mont29 Subscribers: fsiddi Differential Revision: https://developer.blender.org/D4168
Diffstat (limited to 'source/creator')
-rw-r--r--source/creator/creator_args.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index 5b976515dd8..fe67eff3c40 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -1615,6 +1615,7 @@ static int arg_handle_python_file_run(int argc, const char **argv, void *data)
BPY_CTX_SETUP(ok = BPY_execute_filepath(C, filename, NULL));
if (!ok && app_state.exit_code_on_error.python) {
printf("\nError: script failed, file: '%s', exiting.\n", argv[1]);
+ BPY_python_end();
exit(app_state.exit_code_on_error.python);
}
return 1;
@@ -1656,6 +1657,7 @@ static int arg_handle_python_text_run(int argc, const char **argv, void *data)
if (!ok && app_state.exit_code_on_error.python) {
printf("\nError: script failed, text: '%s', exiting.\n", argv[1]);
+ BPY_python_end();
exit(app_state.exit_code_on_error.python);
}
@@ -1687,6 +1689,7 @@ static int arg_handle_python_expr_run(int argc, const char **argv, void *data)
BPY_CTX_SETUP(ok = BPY_execute_string_ex(C, NULL, argv[1], false));
if (!ok && app_state.exit_code_on_error.python) {
printf("\nError: script failed, expr: '%s', exiting.\n", argv[1]);
+ BPY_python_end();
exit(app_state.exit_code_on_error.python);
}
return 1;