Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeakKeyDictionary.__len__ fragile w/ _IterationGuards #65372

Closed
pjenvey opened this issue Apr 7, 2014 · 3 comments
Closed

WeakKeyDictionary.__len__ fragile w/ _IterationGuards #65372

pjenvey opened this issue Apr 7, 2014 · 3 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pjenvey
Copy link
Member

pjenvey commented Apr 7, 2014

BPO 21173
Nosy @pitrou, @pjenvey
Files
  • issue21173-test.diff
  • weakdictlen.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-10-05.18:10:44.398>
    created_at = <Date 2014-04-07.20:17:27.795>
    labels = ['type-bug', 'library']
    title = 'WeakKeyDictionary.__len__ fragile w/ _IterationGuards'
    updated_at = <Date 2014-10-05.18:10:44.396>
    user = 'https://github.com/pjenvey'

    bugs.python.org fields:

    activity = <Date 2014-10-05.18:10:44.396>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-10-05.18:10:44.398>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2014-04-07.20:17:27.795>
    creator = 'pjenvey'
    dependencies = []
    files = ['34751', '36802']
    hgrepos = []
    issue_num = 21173
    keywords = ['patch']
    message_count = 3.0
    messages = ['215716', '228495', '228606']
    nosy_count = 3.0
    nosy_names = ['pitrou', 'pjenvey', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21173'
    versions = ['Python 3.4', 'Python 3.5']

    @pjenvey
    Copy link
    Member Author

    pjenvey commented Apr 7, 2014

    len() on WeakKeyDictionarys can fail with ValueErrors when _IterationGuards are kept alive

    Attached is a test showing this:

    ======================================================================
    ERROR: test_weak_keys_len_destroy_while_iterating (main.MappingTestCase)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "Lib/test/test_weakref.py", line 1336, in test_weak_keys_len_destroy_while_iterating
        self.assertEqual(len(dict), 0)
    ValueError: __len__() should return >= 0

    One probably shouldn't keep them alive like this, but __len__ shouldn't be blowing up either. On non ref counting GC platforms this situation is easier to trigger unintentionally

    @pjenvey pjenvey added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 7, 2014
    @pitrou
    Copy link
    Member

    pitrou commented Oct 4, 2014

    Thank you for reporting this. Here is a patch with tests.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 5, 2014

    New changeset 657d21b4b121 by Antoine Pitrou in branch '3.4':
    Closes bpo-21173: Fix len() on a WeakKeyDictionary when .clear() was called with an iterator alive.
    https://hg.python.org/cpython/rev/657d21b4b121

    New changeset 27533444b964 by Antoine Pitrou in branch 'default':
    Closes bpo-21173: Fix len() on a WeakKeyDictionary when .clear() was called with an iterator alive.
    https://hg.python.org/cpython/rev/27533444b964

    @python-dev python-dev mannequin closed this as completed Oct 5, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants