We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
pickle
test_interpreters
1 parent 1953713 commit 06e347bCopy full SHA for 06e347b
Lib/concurrent/interpreters/__init__.py
@@ -146,12 +146,8 @@ def __del__(self):
146
self._decref()
147
148
# for pickling:
149
- def __getnewargs__(self):
150
- return (self._id,)
151
-
152
- # for pickling:
153
- def __getstate__(self):
154
- return None
+ def __reduce__(self):
+ return (type(self), (self._id,))
155
156
def _decref(self):
157
if not self._ownsref:
Lib/concurrent/interpreters/_queues.py
@@ -129,12 +129,8 @@ def __hash__(self):
129
return hash(self._id)
130
131
132
133
134
135
136
137
138
139
def _set_unbound(self, op, items=None):
140
assert not hasattr(self, '_unbound')
Lib/test/support/channels.py
@@ -105,12 +105,8 @@ def __eq__(self, other):
105
return other._id == self._id
106
107
108
109
- return (int(self._id),)
110
111
112
113
+ return (type(self), (int(self._id),))
114
115
@property
116
def id(self):
Lib/test/test_interpreters/test_api.py
@@ -412,9 +412,11 @@ def test_equality(self):
412
413
def test_pickle(self):
414
interp = interpreters.create()
415
- data = pickle.dumps(interp)
416
- unpickled = pickle.loads(data)
417
- self.assertEqual(unpickled, interp)
+ for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
+ with self.subTest(protocol=protocol):
+ data = pickle.dumps(interp, protocol)
418
+ unpickled = pickle.loads(data)
419
+ self.assertEqual(unpickled, interp)
420
421
422
class TestInterpreterIsRunning(TestBase):
Lib/test/test_interpreters/test_channels.py
@@ -121,9 +121,11 @@ def test_equality(self):
121
122
123
ch, _ = channels.create()
124
- data = pickle.dumps(ch)
125
126
- self.assertEqual(unpickled, ch)
+ data = pickle.dumps(ch, protocol)
127
128
+ self.assertEqual(unpickled, ch)
class TestSendChannelAttrs(TestBase):
@@ -152,9 +154,11 @@ def test_equality(self):
_, ch = channels.create()
158
159
160
161
162
163
164
class TestSendRecv(TestBase):
Lib/test/test_interpreters/test_queues.py
@@ -188,9 +188,11 @@ def test_equality(self):
188
189
190
queue = queues.create()
191
- data = pickle.dumps(queue)
192
193
- self.assertEqual(unpickled, queue)
+ data = pickle.dumps(queue, protocol)
194
195
+ self.assertEqual(unpickled, queue)
196
197
198
class TestQueueOps(TestBase):
Misc/NEWS.d/next/Library/2025-07-05-09-45-04.gh-issue-136286.N67Amr.rst
@@ -0,0 +1,2 @@
1
+Fix pickling failures for protocols 0 and 1 for many objects realted to
2
+subinterpreters.
0 commit comments