File tree Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change 5
5
import sys
6
6
import time
7
7
import typing as t
8
- import weakref
9
8
from functools import partial
10
9
from getpass import getpass
11
10
from queue import Empty
@@ -94,10 +93,7 @@ class KernelClient(ConnectionFileMixin):
94
93
context = Instance (zmq .asyncio .Context )
95
94
96
95
def _context_default (self ) -> zmq .asyncio .Context :
97
- context = zmq .asyncio .Context ()
98
- # Use a finalizer to destroy the context.
99
- self ._finalizer = weakref .finalize (self , context .destroy )
100
- return context
96
+ return zmq .asyncio .Context ()
101
97
102
98
# The classes to use for the various channels
103
99
shell_channel_class = Type (ChannelABC )
@@ -116,6 +112,11 @@ def _context_default(self) -> zmq.asyncio.Context:
116
112
# flag for whether execute requests should be allowed to call raw_input:
117
113
allow_stdin : bool = True
118
114
115
+ def __del__ (self ):
116
+ """Clean up the context when garbage collected."""
117
+ if not self .channels_running :
118
+ self .context .destroy ()
119
+
119
120
# --------------------------------------------------------------------------
120
121
# Channel proxy methods
121
122
# --------------------------------------------------------------------------
Original file line number Diff line number Diff line change 6
6
import socket
7
7
import typing as t
8
8
import uuid
9
- import weakref
10
9
11
10
import zmq
12
11
from traitlets import Any
@@ -107,15 +106,16 @@ def _starting_kernels(self):
107
106
108
107
@default ("context" ) # type:ignore[misc]
109
108
def _context_default (self ) -> zmq .Context :
110
- context = zmq .Context ()
111
- # Use a finalizer to destroy the context.
112
- self ._finalizer = weakref .finalize (self , context .destroy )
113
- return context
109
+ return zmq .Context ()
114
110
115
111
connection_dir = Unicode ("" )
116
112
117
113
_kernels = Dict ()
118
114
115
+ def __del__ (self ):
116
+ """Clean up the context when garbage collected."""
117
+ self .context .destroy ()
118
+
119
119
def list_kernel_ids (self ) -> t .List [str ]:
120
120
"""Return a list of the kernel ids of the active kernels."""
121
121
# Create a copy so we can iterate over kernels in operations
You can’t perform that action at this time.
0 commit comments