python / python/cpython

Free threaded: slicing a shared memoryview raises `ValueError: operation forbidden on released memoryview object`

Open
#155,606 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core topic-free-threading type-bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.