Skip to content

Commit 07d0574

Browse files
authored
Simplified comm lifetime management (jupyter-xeus#701)
1 parent 541de9c commit 07d0574

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

src/xcomm.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace xpyt
8383
m_close_callback = std::move(callback);
8484
m_comm.on_close([this](const xeus::xmessage&)
8585
{
86-
m_close_callback(comm_id());
86+
m_close_callback();
8787
});
8888
}
8989

@@ -128,7 +128,7 @@ namespace xpyt
128128
XPYT_HOLDING_GIL(py_callback(cppmessage_to_pymessage(msg)))
129129
if (m_close_callback)
130130
{
131-
m_close_callback(comm_id());
131+
m_close_callback();
132132
}
133133
};
134134
}
@@ -152,11 +152,10 @@ namespace xpyt
152152
// deletion by the garbage collector
153153
pycomm.inc_ref();
154154
xcomm& comm = pycomm.cast<xcomm&>();
155-
comm.on_close_cleanup([this](std::string id)
155+
comm.on_close_cleanup([pycomm]()
156156
{
157-
XPYT_HOLDING_GIL(m_comms.erase(id))
157+
XPYT_HOLDING_GIL(pycomm.dec_ref())
158158
});
159-
m_comms[comm.comm_id()] = pycomm;
160159
}
161160

162161
/***************

src/xcomm.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace xpyt
2121
{
2222
public:
2323

24-
using close_callback_type = std::function<void(std::string)>;
24+
using close_callback_type = std::function<void()>;
2525
using python_callback_type = std::function<void(py::object)>;
2626
using cpp_callback_type = std::function<void(const xeus::xmessage&)>;
2727
using buffers_sequence = xeus::buffer_sequence;
@@ -58,18 +58,12 @@ namespace xpyt
5858
close_callback_type m_close_callback;
5959
};
6060

61-
class xcomm_manager
61+
struct xcomm_manager
6262
{
63-
public:
64-
6563
xcomm_manager() = default;
6664

6765
void register_target(const py::str& target_name, const py::object& callback);
6866
void register_comm(py::object comm);
69-
70-
private:
71-
72-
std::map<std::string, py::object> m_comms;
7367
};
7468

7569
py::module get_comm_module();

0 commit comments

Comments
 (0)