Skip to content

Commit aa93ab4

Browse files
committed
pyinterp.rs: Emit exitcode on exception in repl
Fixes #208
1 parent a1860ca commit aa93ab4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pyoxidizer/src/pyembed/pyinterp.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::io::Write;
1414
use std::path::PathBuf;
1515
use std::ptr::null;
1616

17-
use cpython::exc::ValueError;
17+
use cpython::exc::{SystemExit, ValueError};
1818
use cpython::{
1919
GILGuard, NoArgs, ObjectProtocol, PyClone, PyDict, PyErr, PyList, PyModule, PyObject, PyResult,
2020
PyString, Python, PythonObject, ToPyObject,
@@ -733,13 +733,17 @@ impl<'a> MainPythonInterpreter<'a> {
733733
.or_else(|_| Err(PyErr::new::<ValueError, _>(py, "could not create CString")))?;
734734
let mut cf = pyffi::PyCompilerFlags { cf_flags: 0 };
735735

736-
// TODO use return value.
737736
unsafe {
738737
let stdin = stdin_to_file();
739-
pyffi::PyRun_AnyFileExFlags(stdin, filename.as_ptr() as *const c_char, 0, &mut cf)
740-
};
738+
let res = pyffi::PyRun_AnyFileExFlags(stdin, filename.as_ptr() as *const c_char, 0, &mut cf);
741739

742-
Ok(py.None())
740+
if res == 0 {
741+
Ok(py.None())
742+
} else {
743+
Err(PyErr::new::<SystemExit, _>(py, 1))
744+
}
745+
746+
}
743747
}
744748

745749
/// Runs Python code provided by a string.

0 commit comments

Comments
 (0)