Skip to content

Commit ff2e981

Browse files
authored
fix input (#704)
fix input
1 parent 20b5bd9 commit ff2e981

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/xinterpreter.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,13 @@ namespace xpyt
131131

132132
// Scope guard performing the temporary monkey patching of input and
133133
// getpass with a function sending input_request messages.
134-
auto input_guard = input_redirection(config.allow_stdin);
134+
auto input_guard = std::make_unique<xpyt::input_redirection>(config.allow_stdin);
135135

136136
std::string ename;
137137
std::string evalue;
138138
std::vector<std::string> traceback;
139139

140-
141-
auto when_done_callback_lambda = [this, cb, config, user_expressions]() {
140+
py::cpp_function when_done_callback([this, cb, config, user_expressions, input_guard = std::move(input_guard)](){
142141
py::gil_scoped_acquire acquire;
143142

144143
// Get payload
@@ -161,13 +160,11 @@ namespace xpyt
161160
}
162161
cb(xeus::create_error_reply(error.m_ename, error.m_evalue, error.m_traceback));
163162
}
164-
};
165-
std::function<void()> when_done_callback = when_done_callback_lambda;
163+
});
166164

167165
try
168166
{
169-
170-
m_ipython_shell.attr("run_cell_async")(code, when_done_callback, "store_history"_a=config.store_history, "silent"_a=config.silent);
167+
m_ipython_shell.attr("run_cell_async")(code, std::move(when_done_callback), "store_history"_a=config.store_history, "silent"_a=config.silent);
171168
}
172169
catch(std::runtime_error& e)
173170
{

0 commit comments

Comments
 (0)