File tree 2 files changed +7
-0
lines changed
2 files changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -560,6 +560,7 @@ def test_shadow(self):
560
560
assert s2 ._shadow_obj is s
561
561
assert s .underlying != p .underlying
562
562
assert s2 .underlying == s .underlying
563
+ assert s2 .context is s .context
563
564
s3 = zmq .Socket (s )
564
565
assert s3 ._shadow_obj is s
565
566
assert s3 .underlying == s .underlying
Original file line number Diff line number Diff line change @@ -133,6 +133,7 @@ def __init__(
133
133
shadow : Socket | int = 0 ,
134
134
copy_threshold : int | None = None ,
135
135
):
136
+ shadow_context : zmq .Context | None = None
136
137
if isinstance (ctx_or_socket , zmq .Socket ):
137
138
# positional Socket(other_socket)
138
139
shadow = ctx_or_socket
@@ -145,6 +146,8 @@ def __init__(
145
146
# hold a reference to the shadow object
146
147
self ._shadow_obj = shadow
147
148
if not isinstance (shadow , int ):
149
+ if isinstance (shadow , zmq .Socket ):
150
+ shadow_context = shadow .context
148
151
try :
149
152
shadow = cast (int , shadow .underlying )
150
153
except AttributeError :
@@ -159,6 +162,9 @@ def __init__(
159
162
shadow = shadow_address ,
160
163
copy_threshold = copy_threshold ,
161
164
)
165
+ if self ._shadow_obj and shadow_context :
166
+ # keep self.context reference if shadowing a Socket object
167
+ self .context = shadow_context
162
168
163
169
try :
164
170
socket_type = cast (int , self .get (zmq .TYPE ))
You can’t perform that action at this time.
0 commit comments