[issue19542] WeakValueDictionary bug in setdefault()pop()
Antoine Pitrou added the comment: Yes, we need to fix this. Sorry for being a bit slow. -- versions: +Python 3.5, Python 3.6 -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Tin Tvrtković added the comment: We're actually getting bitten by this in production through the Riak Python client, so this isn't a strictly theoretical problem. -- nosy: +tinchester ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Armin Rigo added the comment: Converted the test into an official test, which fails; and wrote the patch for CPython 3.trunk and for CPython 2.7. Please review and commit. -- keywords: +needs review -patch stage: needs patch - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Changes by Armin Rigo ar...@users.sourceforge.net: Added file: http://bugs.python.org/file37993/fix-weakvaluedict-2.7.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Changes by Armin Rigo ar...@users.sourceforge.net: -- keywords: +patch Added file: http://bugs.python.org/file37992/fix-weakvaluedict.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Antoine Pitrou added the comment: Changeset ea70032a24b1 is where the pop(*args) thing comes from. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Changes by Ned Deily n...@acm.org: -- nosy: +fdrake, pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Antoine Pitrou added the comment: I think the underlying question is: are weak dicts otherwise MT-safe? -- versions: +Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Armin Rigo added the comment: As you can see in x.py, the underlying question is rather: are weakdicts usable in a single thread of a multithreaded program? I believe that this question cannot reasonably be answered No, independently on the answer you want to give to your own question. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Antoine Pitrou added the comment: Ah, you're right. We just need to cook up a patch then. -- stage: - needs patch type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Tim Peters added the comment: The weakref.slice fix looks solid to me, although it appears to be specific to 2.7 (the methods are fancier on the current default branch, fiddling with self._pending_removals too). Does anyone know why the signature of pop is: def pop(self, key, *args) ? It doesn't make sense to me to accept any number of arguments following `key`. Perhaps it's just an obscure way to avoid doing: _noarg = object() # unique sentinel def pop(self, key, default=_noarg): ? -- nosy: +tim.peters ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
New submission from Armin Rigo: WeakValueDictionary.setdefault() contains a bug that shows up in multithreaded situations using reference cycles. Attached a test case: it is possible for 'setdefault(key, default)' to return None, although None is never put as a value in the dictionary. (Actually, being a WeakValueDictionary, None is not allowed as a value.) The reason is that the code in setdefault() ends in return wr(), but the weakref wr might have gone invalid between the time it was fetched from self.data and the wr() itself, thus returning None. A similar problem occurs in pop(), leading it to possibly raise KeyError even if it is called with a default argument. -- components: Library (Lib) messages: 202510 nosy: arigo priority: normal severity: normal status: open title: WeakValueDictionary bug in setdefault()pop() versions: Python 2.7, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Changes by Armin Rigo ar...@users.sourceforge.net: Added file: http://bugs.python.org/file32557/x.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19542] WeakValueDictionary bug in setdefault()pop()
Changes by Armin Rigo ar...@users.sourceforge.net: Added file: http://bugs.python.org/file32558/weakref.slice ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19542 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com