Fix exit in command line runner (#3241)

Don't set error code to 1 if the program calls exit(0)!
This commit is contained in:
Hood Chatham 2022-11-09 21:37:36 -08:00 committed by GitHub
parent 9952a86f0f
commit 92a1a5c014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 4 deletions

View File

@ -20,8 +20,8 @@ substitutions:
- {{ Enhancement }} Added a system for making Pyodide virtual environments. This
is for testing out of tree builds. For more information, see [the
documentation](https://pyodide.org/en/stable/development/out-of-tree.html).
{pr}`2976`, {pr}`3039`, {pr}`3040`, {pr}`3044`, {pr}`3044`, {pr}`3096`,
{pr}`3098`, {pr}`3108`, {pr}`3109`
{pr}`2976`, {pr}`3039`, {pr}`3040`, {pr}`3044`, {pr}`3096`, {pr}`3098`,
{pr}`3108`, {pr}`3109`, {pr}`3241`
- {{ Enhancement }} Users can do a static import of `pyodide/pyodide.asm.js` to
avoid issues with dynamic imports. This allows the use of Pyodide with

View File

@ -425,3 +425,22 @@ def test_pypa_index(tmp_path):
stdout.strip().rsplit("\n", 1)[-1]
== "Successfully installed attrs-* micropip-* numpy-* sharedlib-test-py-*"
)
def test_sys_exit(selenium, venv):
result = subprocess.run(
[venv / "bin/python", "-c", "import sys; sys.exit(0)"],
capture_output=True,
encoding="utf-8",
)
assert result.returncode == 0
assert result.stdout == ""
assert result.stderr == ""
result = subprocess.run(
[venv / "bin/python", "-c", "import sys; sys.exit(12)"],
capture_output=True,
encoding="utf-8",
)
assert result.returncode == 12
assert result.stdout == ""
assert result.stderr == ""

View File

@ -241,8 +241,12 @@ async function main() {
try {
errcode = py._module._run_main();
} catch (e) {
// If there is some sort of error, add the Python tracebook in addition
// to the JavaScript traceback
// If someone called exit, just exit with the right return code.
if(e.constructor.name === "ExitStatus"){
process.exit(e.status);
}
// Otherwise if there is some sort of error, include the Python
// tracebook in addition to the JavaScript traceback
py._module._dump_traceback();
throw e;
}