Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shutdown and cleanup behavior #772

Merged
merged 22 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more cleanup
  • Loading branch information
blink1073 committed Apr 17, 2022
commit 9dbe109e339e4a63cab342d83822a9487a8620c9
5 changes: 4 additions & 1 deletion jupyter_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def _context_default(self) -> zmq.asyncio.Context:
# flag for whether execute requests should be allowed to call raw_input:
allow_stdin: bool = True

def __del__(self):
"""Destroy our context when we are garbage collected."""
self.context.destroy()

# --------------------------------------------------------------------------
# Channel proxy methods
# --------------------------------------------------------------------------
Expand Down Expand Up @@ -320,7 +324,6 @@ def stop_channels(self) -> None:
self.control_channel.stop()
if self._created_context:
self._created_context = False
self.context.destroy()

@property
def channels_running(self) -> bool:
Expand Down
4 changes: 3 additions & 1 deletion jupyter_client/tests/test_multikernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ def test_start_sequence_ipc_kernels(self):

def tcp_lifecycle_with_loop(self):
# Ensure each thread has an event loop
asyncio.set_event_loop(asyncio.new_event_loop())
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
self.test_tcp_lifecycle()
loop.close()

def test_start_parallel_thread_kernels(self):
self.test_tcp_lifecycle()
Expand Down