Skip to content

Commit 9dbe109

Browse files
committed
more cleanup
1 parent 164f45d commit 9dbe109

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

jupyter_client/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def _context_default(self) -> zmq.asyncio.Context:
116116
# flag for whether execute requests should be allowed to call raw_input:
117117
allow_stdin: bool = True
118118

119+
def __del__(self):
120+
"""Destroy our context when we are garbage collected."""
121+
self.context.destroy()
122+
119123
# --------------------------------------------------------------------------
120124
# Channel proxy methods
121125
# --------------------------------------------------------------------------
@@ -320,7 +324,6 @@ def stop_channels(self) -> None:
320324
self.control_channel.stop()
321325
if self._created_context:
322326
self._created_context = False
323-
self.context.destroy()
324327

325328
@property
326329
def channels_running(self) -> bool:

jupyter_client/tests/test_multikernelmanager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ def test_start_sequence_ipc_kernels(self):
160160

161161
def tcp_lifecycle_with_loop(self):
162162
# Ensure each thread has an event loop
163-
asyncio.set_event_loop(asyncio.new_event_loop())
163+
loop = asyncio.new_event_loop()
164+
asyncio.set_event_loop(loop)
164165
self.test_tcp_lifecycle()
166+
loop.close()
165167

166168
def test_start_parallel_thread_kernels(self):
167169
self.test_tcp_lifecycle()

0 commit comments

Comments
 (0)