Free threaded: slicing a shared memoryview raises `ValueError: operation forbidden on released memoryview object`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
Hello (and thanks for your amazing work),
I found that, on free threading Python, slicing a shared memoryview from several threads raises ValueError: operation forbidden on released memoryview object, even though nothing calls .release() and the underlying object is an immutable bytes. Stock (GIL) builds are unaffected.
data = bytes(1 << 20)
mv = memoryview(data) # ONE view, shared
# in each of 8 threads: bytes(mv[0:64])
See the attached reproduction script. Results are not deterministic: not all threads raise an exception. Here are the results on my machine after running it:
$ PYTHON_GIL=0 python3.15t repro_shared_memoryview_threads.py
python 3.15.0rc1 gil_enabled=False: 3/8 threads FAILED -> ValueError('operation forbidden on released memoryview object')
$ PYTHON_GIL=1 python3.15t repro_shared_memoryview_threads.py
python 3.15.0rc1 gil_enabled=True: all 8 threads OK
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Linked PRs
- gh-155882
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached repro_shared_memoryview_threads.py script and compare its results under PYTHON_GIL=0 and PYTHON_GIL=1 on Python 3.15. Investigate the shared memoryview behavior in the free-threaded runtime; done means concurrent slicing no longer raises the reported ValueError. Linked PR gh-155882 indicates work is already underway.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100