py: Add config option to print warnings/errors to stderr.

This adds a new configuration option to print runtime warnings and errors to
stderr. On Unix, CPython prints warnings and unhandled exceptions to stderr,
so the unix port here is configured to use this option.

The unix port already printed unhandled exceptions on the main thread to
stderr. This patch fixes unhandled exceptions on other threads and warnings
(issue #2838) not printing on stderr.

Additionally, a couple tests needed to be fixed to handle this new behavior.
This is done by also capturing stderr when running tests.
This commit is contained in:
David Lechner
2017-09-24 20:15:48 -05:00
committed by Damien George
parent 9d836fedbd
commit 62849b7010
5 changed files with 17 additions and 9 deletions

View File

@@ -192,10 +192,10 @@ STATIC void *thread_entry(void *args_in) {
// swallow exception silently
} else {
// print exception out
mp_printf(&mp_plat_print, "Unhandled exception in thread started by ");
mp_obj_print_helper(&mp_plat_print, args->fun, PRINT_REPR);
mp_printf(&mp_plat_print, "\n");
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(exc));
mp_printf(MICROPY_ERROR_PRINTER, "Unhandled exception in thread started by ");
mp_obj_print_helper(MICROPY_ERROR_PRINTER, args->fun, PRINT_REPR);
mp_printf(MICROPY_ERROR_PRINTER, "\n");
mp_obj_print_exception(MICROPY_ERROR_PRINTER, MP_OBJ_FROM_PTR(exc));
}
}