Skip to content

Commit

Permalink
more context cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Apr 24, 2022
1 parent a50d602 commit 523ba88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions jupyter_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ def _context_default(self) -> zmq.asyncio.Context:
allow_stdin: bool = True

def __del__(self):
"""Handle garbage collection. Destroy context if applicable."""
if self._created_context and self.context and not self.context.closed:
if self.log:
self.log.debug("Destroying zmq context for %s", self)
self.context.destroy()
if self.channels_running:
if self.log:
self.log.warning("Could not destroy zmq context for %s", self)
else:
if self.log:
self.log.debug("Destroying zmq context for %s", self)
self.context.destroy()
try:
super_del = super().__del__
except AttributeError:
Expand Down
1 change: 1 addition & 0 deletions jupyter_client/multikernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def _context_default(self) -> zmq.Context:
_kernels = Dict()

def __del__(self):
"""Handle garbage collection. Destroy context if applicable."""
if self._created_context and self.context and not self.context.closed:
if self.log:
self.log.debug("Destroying zmq context for %s", self)
Expand Down

0 comments on commit 523ba88

Please sign in to comment.