python / python/cpython

`queue.SimpleQueue.__sizeof__()` ignores the underlying data structure

Aperta
#140,025 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

extension-modules type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

queue.SimpleQueue (C level) uses a list on Python < 3.13[1][2][3][4], a ring buffer on Python >= 3.13[5][6]. However, it does not implement its own __sizeof__() method, and as a result, only the size of the simplequeueobject structure itself (basicsize) is taken as the size of the object, while the size of the underlying structure is ignored.

>>> from queue import SimpleQueue
>>> q = SimpleQueue()
>>> q.__sizeof__()
72  # 56 on Python < 3.13
>>> for _ in range(1_000):
...     q.put(object())
...     
>>> q.__sizeof__()
72  # 56 on Python < 3.13

Expected (should be, on Python >= 3.13):

>>> from queue import SimpleQueue
>>> q = SimpleQueue()
>>> q.__sizeof__()
136  # == 72 + 8*8 == sizeof(simplequeueobject) + sizeof(PyObject *)*INITIAL_RING_BUF_CAPACITY
>>> for _ in range(1_000):
...     q.put(object())
...     
>>> q.__sizeof__()
8264  # == 72 + 8*1024 == sizeof(simplequeueobject) + sizeof(PyObject *)*pow(2, ceil(log2(1000)))
CPython versions tested on:

3.9, 3.10, 3.11, 3.12, 3.13, 3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-140086
  • gh-143137
  • gh-143277

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da Modules/_queuemodule.c, concentrandoti sulle implementazioni di SimpleQueue collegate nel report e sul calcolo delle relative dimensioni. Esegui le riproduzioni fornite nelle versioni di Python pertinenti, quindi verifica che le dimensioni riportate includano la lista o il buffer circolare sottostante e corrispondano ai valori attesi indicati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.