This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger
Date 2011-12-03.00:30:27
SpamBayes Score 5.694156e-06
Marked as misclassified No
Message-id <1322872228.97.0.525171057572.issue13521@psf.upfronthosting.co.za>
In-reply-to
Content
A dialog on python-dev suggests that dict.setdefault() was intended to be atomic and that a number of experienced developers have deployed code relying on its atomicity:  http://mail.python.org/pipermail/python-3000/2007-July/008693.html

The actual implementation shows a second call to PyDict_Setitem() which can call PyObject_Hash() which can call arbitrary Python code.   http://hg.python.org/cpython/file/2.7/Objects/dictobject.c#l1937

This fix is straight-forward, use the results of the initial lookup to insert the default object.  This will make the operation atomic and it will make it faster.
History
Date User Action Args
2011-12-03 00:30:29rhettingersetrecipients: + rhettinger
2011-12-03 00:30:28rhettingersetmessageid: <1322872228.97.0.525171057572.issue13521@psf.upfronthosting.co.za>
2011-12-03 00:30:28rhettingerlinkissue13521 messages
2011-12-03 00:30:27rhettingercreate