Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/xinterpreter_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ namespace xpyt
py::module context_module = get_request_context_module();
}

namespace
{
class splinter_cell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

{
public:

splinter_cell()
{
auto null_out = py::cpp_function([](const std::string&) {});

py::module sys = py::module::import("sys");
m_stdout_func = sys.attr("stdout").attr("write");
m_stderr_func = sys.attr("stderr").attr("write");
sys.attr("stdout").attr("write") = null_out;
sys.attr("stderr").attr("write") = null_out;
}

~splinter_cell()
{
py::module sys = py::module::import("sys");
sys.attr("stdout").attr("write") = m_stdout_func;
sys.attr("stderr").attr("write") = m_stderr_func;
}

private:

py::object m_stdout_func;
py::object m_stderr_func;
};
}

void raw_interpreter::execute_request_impl(
send_reply_callback cb,
int execution_count,
Expand Down Expand Up @@ -138,7 +169,7 @@ namespace xpyt
// If the last statement is an expression, we compile it separately
// in an interactive mode (This will trigger the display hook)
py::object last_stmt = expressions[py::len(expressions) - 1];
if (py::isinstance(last_stmt, ast.attr("Expr")))
if (py::isinstance(last_stmt, ast.attr("Expr")) && !config.silent)
{
code_ast.attr("body").attr("pop")();

Expand All @@ -161,6 +192,7 @@ namespace xpyt
}
else
{
splinter_cell guard;
py::object compiled_code = builtins.attr("compile")(code_ast, filename, "exec");
exec(compiled_code);
}
Expand Down
Loading