Skip to content

Commit

Permalink
Fixed the debugger not starting (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille authored Jun 21, 2024
1 parent 8182ac7 commit 1bb6d4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/xdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ namespace xpyt
std::string controller_header_end_point = xeus::get_controller_end_point("debugger_header");
std::string publisher_end_point = xeus::get_publisher_end_point();

bind_sockets(controller_end_point, controller_header_end_point);
bind_sockets(controller_header_end_point, controller_end_point);

std::string debugpy_end_point = "tcp://" + m_debugpy_host + ':' + m_debugpy_port;
std::thread client(&xdap_tcp_client::start_debugger,
Expand Down
24 changes: 21 additions & 3 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ namespace xpyt
try
{
exec(py::str(code));

reply["status"] = "ok";
}
catch (py::error_already_set& e)
Expand Down Expand Up @@ -361,12 +360,31 @@ namespace xpyt
context_module.attr("set_request_context")(context);
}

namespace
{
xeus::xrequest_context empty_request_context{};
}

const xeus::xrequest_context& interpreter::get_request_context() const noexcept
{
py::gil_scoped_acquire acquire;
py::module context_module = get_request_context_module();
py::object res = context_module.attr("get_request_context")();
return *(res.cast<xeus::xrequest_context*>());
// When the debugger is started, it send some python code to execute, that triggers
// a call to publish_stream, and ultimately to this function. However:
// - we are out of the handling of an execute_request, therefore set_request_context
// has not been called
// - we cannot set it from another thread (the context of the context variable would
// be different)
// Therefore, we have to catch the exception thrown when the context variable is empty.
try
{
py::object res = context_module.attr("get_request_context")();
return *(res.cast<xeus::xrequest_context*>());
}
catch (py::error_already_set& e)
{
return empty_request_context;
}
}

void interpreter::redirect_output()
Expand Down

0 comments on commit 1bb6d4c

Please sign in to comment.