Skip to content

concurrent.interpreters.NotShareableError: object could not be unpickled #142572

@note35

Description

@note35

Bug report

Bug description:

Context:

  1. ./python -m test test_interpreters test_struct fails with: KeyError: concurrent.interpreters._queues.UNBOUND #142414 (comment)
  2. 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_struct fails 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions