Skip to content

Commit 523ba88

Browse files
committed
more context cleanup
1 parent a50d602 commit 523ba88

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

jupyter_client/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,15 @@ def _context_default(self) -> zmq.asyncio.Context:
117117
allow_stdin: bool = True
118118

119119
def __del__(self):
120+
"""Handle garbage collection. Destroy context if applicable."""
120121
if self._created_context and self.context and not self.context.closed:
121-
if self.log:
122-
self.log.debug("Destroying zmq context for %s", self)
123-
self.context.destroy()
122+
if self.channels_running:
123+
if self.log:
124+
self.log.warning("Could not destroy zmq context for %s", self)
125+
else:
126+
if self.log:
127+
self.log.debug("Destroying zmq context for %s", self)
128+
self.context.destroy()
124129
try:
125130
super_del = super().__del__
126131
except AttributeError:

jupyter_client/multikernelmanager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def _context_default(self) -> zmq.Context:
116116
_kernels = Dict()
117117

118118
def __del__(self):
119+
"""Handle garbage collection. Destroy context if applicable."""
119120
if self._created_context and self.context and not self.context.closed:
120121
if self.log:
121122
self.log.debug("Destroying zmq context for %s", self)

0 commit comments

Comments
 (0)