Skip to content

Commit

Permalink
bootloader: return 1 if frozen python script exits due to exception
Browse files Browse the repository at this point in the history
Keep the bootloader's return code consistent with that of python
interpreter, which returns 1 if it exits due to exception in the
python script.

Fixes pyinstaller#5480.
  • Loading branch information
rokm committed Jan 17, 2021
1 parent f95eb3e commit 6410b33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion bootloader/src/pyi_launch.c
Expand Up @@ -516,7 +516,10 @@ pyi_launch_run_scripts(ARCHIVE_STATUS *status)
}
#endif /* if defined(WINDOWED) and defined(LAUNCH_DEBUG) */

return -1;
/* Be consistent with python interpreter, which returns
* 1 if it exits due to unhandled exception.
*/
return 1;
}
free(data);
}
Expand Down
3 changes: 3 additions & 0 deletions news/5480.bugfix.rst
@@ -0,0 +1,3 @@
Fix the return code if the frozen script fails due to unhandled exception.
The return code 1 is used instead of -1, to keep the behavior consistent
with that of the python interpreter.
3 changes: 2 additions & 1 deletion tests/unit/test_systemexit.py
Expand Up @@ -27,7 +27,8 @@
('import sys; sys.exit()', 0),
('raise SystemExit(1)', 1),
('import sys; sys.exit(2)', 2),
('raise SystemExit("Message to get printed to the console.")', 1)
('raise SystemExit("Message to get printed to the console.")', 1),
('raise Exception("Unhandled exception.")', 1) # See issue #5480
]
)
def test_systemexit_is_handled_correctly(src, retcode, pyi_builder):
Expand Down

0 comments on commit 6410b33

Please sign in to comment.