77import typing as t
88import uuid
99from functools import partial
10- from threading import Lock , current_thread , main_thread
10+ from threading import Lock , current_thread
1111
1212import zmq
1313from tornado .ioloop import IOLoop
@@ -41,7 +41,7 @@ def __init__(
4141 shell_socket : zmq .Socket [t .Any ],
4242 ):
4343 """Initialize the subshell manager."""
44- assert current_thread () == main_thread ()
44+ self . _parent_thread = current_thread ()
4545
4646 self ._context : zmq .Context [t .Any ] = context
4747 self ._shell_channel_io_loop = shell_channel_io_loop
@@ -127,7 +127,7 @@ def set_on_recv_callback(self, on_recv_callback):
127127 """Set the callback used by the main shell and all subshells to receive
128128 messages sent from the shell channel thread.
129129 """
130- assert current_thread () == main_thread ()
130+ assert current_thread () == self . _parent_thread
131131 self ._on_recv_callback = on_recv_callback
132132 self ._shell_channel_to_main .on_recv (IOLoop .current (), partial (self ._on_recv_callback , None ))
133133
@@ -144,7 +144,7 @@ def subshell_id_from_thread_id(self, thread_id: int) -> str | None:
144144 Only used by %subshell magic so does not have to be fast/cached.
145145 """
146146 with self ._lock_cache :
147- if thread_id == main_thread () .ident :
147+ if thread_id == self . _parent_thread .ident :
148148 return None
149149 for id , subshell in self ._cache .items ():
150150 if subshell .ident == thread_id :
0 commit comments