Skip to content

queue.SimpleQueue.__sizeof__() ignores the underlying data structure #140025

Closed

Description

@x42005e1f

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

Activity

  1. pitrou commented on Oct 14, 2025

    @pitrou
    Member

    I'm going to unassign myself as I'm not really active anymore.

  2. removed their assignment
    on Oct 14, 2025
  3. pitrou commented on Oct 14, 2025

    @pitrou
    Member
  4. added 3 commits that reference this issue on Oct 14, 2025
    c56f4a9
    b4d8b41
    08e4869
  5. added a commit that references this issue on Dec 29, 2025
    ce19aa4
  6. picnixz commented on Dec 30, 2025

    @picnixz
    Member

    Removing the easy label because we already have a PR for that. For newcomers, don't create a PR if one already exists.

  7. added a commit that references this issue on Jan 8, 2026
  8. added a commit that references this issue on Jan 12, 2026
  9. added a commit that references this issue on Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions