Skip to content

Commit 74272e9

Browse files
authored
Creates and register the comm target when it does not exist (#698)
1 parent f56b855 commit 74272e9

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/xcomm.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ namespace xpyt
8484

8585
const xeus::xtarget* xcomm::target(const py::object& target_name) const
8686
{
87-
return xeus::get_interpreter().comm_manager().target(target_name.cast<std::string>());
87+
auto& comm_manager = xeus::get_interpreter().comm_manager();
88+
auto res = comm_manager.target(target_name.cast<std::string>());
89+
if (!res)
90+
{
91+
comm_manager.register_comm_target(
92+
target_name.cast<std::string>(), [](xeus::xcomm&&, const xeus::xmessage&) {}
93+
);
94+
}
95+
return comm_manager.target(target_name.cast<std::string>());
8896
}
8997

9098
xeus::xguid xcomm::id(const py::kwargs& kwargs) const

src/xcomm.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ namespace xpyt
4040

4141
private:
4242

43+
// Warning: this function creates and register the target with a dummy
44+
// comm_open handler when the target does not exist, so that create_comm
45+
// has the same behavior as ipykernel.
4346
const xeus::xtarget* target(const py::object& target_name) const;
4447
xeus::xguid id(const py::kwargs& kwargs) const;
4548
cpp_callback_type cpp_callback(const python_callback_type& callback) const;

0 commit comments

Comments
 (0)