Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

__len__ method of weakset #58367

Closed
Closed

Description

@YurySelivanov
BPO 14159
Nosy @rhettinger, @pitrou
Files
  • weakset_len.patch: patch for WeakSet.len method
  • weaksetlen.patch
  • weaksetlen2.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 2012-03-01.15:39:51.236>
    created_at = <Date 2012-02-29.14:55:23.372>
    labels = ['library', 'type-crash']
    title = '__len__ method of weakset'
    updated_at = <Date 2012-03-01.15:39:51.235>
    user = 'https://bugs.python.org/YurySelivanov'

    bugs.python.org fields:

    activity = <Date 2012-03-01.15:39:51.235>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-03-01.15:39:51.236>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2012-02-29.14:55:23.372>
    creator = 'Yury.Selivanov'
    dependencies = []
    files = ['24681', '24682', '24683']
    hgrepos = []
    issue_num = 14159
    keywords = ['patch']
    message_count = 8.0
    messages = ['154636', '154644', '154647', '154648', '154689', '154699', '154700', '154701']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'pitrou', 'Yury.Selivanov', 'python-dev']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue14159'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    Activity

    1. YurySelivanov commented on Feb 29, 2012

      YurySelivanovmannequin
      MannequinAuthor

      WeakSet has a bug in its '__len__' method, where it performs iteration though 'self.data' without ensuring _IterationGuard.

      This leads to some hard to catch errors with the following traceback:

      builtins.RuntimeError: Set changed size during iteration

      File /usr/lib64/python3.2/_weakrefset.py, line 66, in __len__
          return sum(x() is not None for x in self.data)
      File /usr/lib64/python3.2/_weakrefset.py, line 66, in <genexpr>
          return sum(x() is not None for x in self.data)
      
    2. added
      stdlib
      type-crash
      on Feb 29, 2012
    3. pitrou commented on Feb 29, 2012

      @pitrou
      Member

      I can't find a way to reproduce as a unit test.
      Here is a patch making __len__ O(1) as well (instead of O(n)). Could you try it?

      (note : AFAICT, a similar issue exists for weak dicts)

    4. pitrou commented on Feb 29, 2012

      @pitrou
      Member

      New patch addressing similar issue with weak dicts, and adding more tests.

    5. YurySelivanov commented on Feb 29, 2012

      YurySelivanovmannequin
      MannequinAuthor

      Yes, I couldn't reproduce it either. However it frequently occurs on our buildbot, so tomorrow I'll give you an update if this patch resolves the issue or not.

      In any way, your patch fixes the current implementation at least from the performance perspective. I think it should be applied to 'WeakValueDictionary.__len__' as well.

      Thanks!

    6. YurySelivanov commented on Mar 1, 2012

      YurySelivanovmannequin
      MannequinAuthor

      As expected, it seems that the patch fixes the issue.

    7. python-dev commented on Mar 1, 2012

      python-devmannequin
      Mannequin

      New changeset 1cd0688ff004 by Antoine Pitrou in branch '3.2':
      Issue bpo-14159: Fix the len() of weak containers (WeakSet, WeakKeyDictionary, WeakValueDictionary) to return a better approximation when some objects are dead or dying.
      http://hg.python.org/cpython/rev/1cd0688ff004

      New changeset b1b2a29d3d81 by Antoine Pitrou in branch 'default':
      Issue bpo-14159: Fix the len() of weak containers (WeakSet, WeakKeyDictionary, WeakValueDictionary) to return a better approximation when some objects are dead or dying.
      http://hg.python.org/cpython/rev/b1b2a29d3d81

    8. python-dev commented on Mar 1, 2012

      python-devmannequin
      Mannequin

      New changeset b6acfbe2bdbe by Antoine Pitrou in branch '2.7':
      Issue bpo-14159: Fix the len() of weak sets to return a better approximation when some objects are dead or dying.
      http://hg.python.org/cpython/rev/b6acfbe2bdbe

    9. pitrou commented on Mar 1, 2012

      @pitrou
      Member

      2.7 didn't have the weak dict issue, but I still backported the tests there. Closing, should be fixed now. Thanks for reporting!

    10. transferred this issue fromon Apr 10, 2022
    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

      stdlibtype-crash

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions