Repository navigation
concurrent.interpreters.NotShareableError: object could not be unpickled #142572
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Context:
./python -m test test_interpreters test_structfails with: KeyError: concurrent.interpreters._queues.UNBOUND #142414 (comment)- gh-142414: Unify UNBOUND in Lib/concurrent/interpreters/_queues.py and Lib/concurrent/interpreters/_crossinterp.py. #142515 should fix the issue found in
./python -m test test_interpreters test_structfails with: KeyError: concurrent.interpreters._queues.UNBOUND #142414.
And during the time I was exploring the singleton removal, I found out it's possible, but the test may miss an edge case:
from concurrent import interpreters
from concurrent.interpreters import _queues as queues
import unittest
class Tests(unittest.TestCase):
def test_cross_interpreter_unbound_identity(self):
# Prepare shared queues.
input_q = interpreters.create_queue()
input_q.put(queues.UNBOUND)
result_q = interpreters.create_queue()
# Create a sub-interpreter.
interp = interpreters.create()
interp.prepare_main({"input_q": input_q, "result_q": result_q})
# Run and compare the items in queue.
interp.exec("""
from concurrent.interpreters import _queues as queues
obj = input_q.get()
is_identical = (obj is queues.UNBOUND)
result_q.put(is_identical)
""")
is_identical = result_q.get()
self.assertTrue(is_identical, "UNBOUND identity mismatch across interpreters")
if __name__ == "__main__":
unittest.main()This test is failed without making the object picklable:
ERROR: test_cross_interpreter_unbound_identity (__main__.Tests.test_cross_interpreter_unbound_identity)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/google/home/kirchou/lamdef/cpython/Lib/test/test_addd.py", line 17, in test_cross_interpreter_unbound_identity
interp.exec("""
~~~~~~~~~~~^^^^
from concurrent.interpreters import _queues as queues
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
result_q.put(is_identical)
^^^^^^^^^^^^^^^^^^^^^^^^^^
""")
^^^^
File "/usr/local/google/home/kirchou/lamdef/cpython/Lib/concurrent/interpreters/__init__.py", line 217, in exec
raise ExecutionFailed(excinfo)
concurrent.interpreters.ExecutionFailed: concurrent.interpreters.NotShareableError: object could not be unpickled
Uncaught in the interpreter:
Traceback (most recent call last):
File "/usr/local/google/home/kirchou/lamdef/cpython/Lib/concurrent/interpreters/_crossinterp.py", line 65, in __new__
raise Exception(f'use {cls._MODULE}.{cls._NAME}')
Exception: use concurrent.interpreters._crossinterp.UNBOUND
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<script>", line 3, in <module>
File "/usr/local/google/home/kirchou/lamdef/cpython/Lib/concurrent/interpreters/_queues.py", line 261, in get
obj, unboundop = _queues.get(self._id)
~~~~~~~~~~~^^^^^^^^^^
concurrent.interpreters.NotShareableError: object could not be unpickled
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
note35 commentedon Dec 11, 2025
Filed this bug based on the suggestion of @ZeroIntensity in PR: #142515
Discussion is ongoing...
ZeroIntensity commentedon Dec 11, 2025
Sorry, this isn't what I meant. I thought there was an existing bug in the code, not something introduced by that PR. My apologies for the noise and confusion.
note35 commentedon Dec 11, 2025
Actually it may be okay to open this issue again.
Updated the title, and the content of the bug.
Linked PR to here, please check this commit first - b128769
(This PR contains things that is being handled in #142414.)
[-]Make a none-singleton pickleable for UNBOUND object in Lib/concurrent/interpreters/_crossinterp.py[/-][+]concurrent.interpreters.NotShareableError: object could not be unpickled[/+]pythongh-142572: Fix data race when accessing func_code in PyFunction…