@@ -92,7 +92,10 @@ def __init__(self, socket, pipe=False):
92
92
# ensure all of our sockets as sync zmq.Sockets
93
93
# don't create async wrappers until we are within the appropriate coroutines
94
94
self .socket : zmq .Socket [bytes ] | None = zmq .Socket (socket )
95
- self ._sync_context : zmq .Context [zmq .Socket [bytes ]] = zmq .Context (socket .context )
95
+ if self .socket .context is None :
96
+ # bug in pyzmq, shadow socket doesn't always inherit context attribute
97
+ self .socket .context = socket .context
98
+ self ._context = socket .context
96
99
97
100
self .background_socket = BackgroundSocket (self )
98
101
self ._main_pid = os .getpid ()
@@ -112,8 +115,7 @@ def __init__(self, socket, pipe=False):
112
115
113
116
def _setup_event_pipe (self ):
114
117
"""Create the PULL socket listening for events that should fire in this thread."""
115
- ctx = self ._sync_context
116
- self ._pipe_in0 = ctx .socket (zmq .PULL )
118
+ self ._pipe_in0 = self ._context .socket (zmq .PULL , socket_class = zmq .Socket )
117
119
self ._pipe_in0 .linger = 0
118
120
119
121
_uuid = b2a_hex (os .urandom (16 )).decode ("ascii" )
@@ -147,7 +149,8 @@ def _event_pipe(self):
147
149
event_pipe = self ._local .event_pipe
148
150
except AttributeError :
149
151
# new thread, new event pipe
150
- event_pipe = self ._sync_context .socket (zmq .PUSH )
152
+ # create sync base socket
153
+ event_pipe = self ._context .socket (zmq .PUSH , socket_class = zmq .Socket )
151
154
event_pipe .linger = 0
152
155
event_pipe .connect (self ._event_interface )
153
156
self ._local .event_pipe = event_pipe
@@ -184,12 +187,12 @@ async def _handle_event(self):
184
187
185
188
def _setup_pipe_in (self ):
186
189
"""setup listening pipe for IOPub from forked subprocesses"""
187
- ctx = self ._sync_context
190
+ ctx = self ._context
188
191
189
192
# use UUID to authenticate pipe messages
190
193
self ._pipe_uuid = os .urandom (16 )
191
194
192
- self ._pipe_in1 = ctx .socket (zmq .PULL )
195
+ self ._pipe_in1 = ctx .socket (zmq .PULL , socket_class = zmq . Socket )
193
196
self ._pipe_in1 .linger = 0
194
197
195
198
try :
0 commit comments