Skip to content

Commit 1058a86

Browse files
authored
Stop all channels to allow ZMQContext to properly cleanup between calls (#183)
1 parent 215950e commit 1058a86

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

jupyter_resource_usage/api.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,13 @@ async def get(self, matched_part=None, *args, **kwargs):
122122
timeout_ms = 10_000
123123
events = dict(await poller.poll(timeout_ms))
124124
if control_socket not in events:
125-
self.write(
126-
json.dumps(
127-
{
128-
"content": {"reason": "timeout", "timeout_ms": timeout_ms},
129-
"kernel_id": kernel_id,
130-
}
131-
)
125+
out = json.dumps(
126+
{
127+
"content": {"reason": "timeout", "timeout_ms": timeout_ms},
128+
"kernel_id": kernel_id,
129+
}
132130
)
131+
133132
else:
134133
res = client.control_channel.get_msg(timeout=0)
135134
if isawaitable(res):
@@ -138,4 +137,6 @@ async def get(self, matched_part=None, *args, **kwargs):
138137
res = await res
139138
if res:
140139
res["kernel_id"] = kernel_id
141-
self.write(json.dumps(res, default=date_default))
140+
out = json.dumps(res, default=date_default)
141+
client.stop_channels()
142+
self.write(out)

0 commit comments

Comments
 (0)