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 mjuric
Recipients mjuric
Date 2011-04-19.08:28:23
SpamBayes Score 4.213649e-09
Marked as misclassified No
Message-id <1303201704.87.0.690807992306.issue11875@psf.upfronthosting.co.za>
In-reply-to
Content
The implementation of OrderedDict.__reduce__() in Python 2.7.1 is not thread safe because of the following four lines:

        tmp = self.__map, self.__root
        del self.__map, self.__root
        inst_dict = vars(self).copy()
        self.__map, self.__root = tmp

If one thread is pickling an OrderedDict, while another accesses it, a race condition occurs if the accessing thread accesses the dict after self.__map and self.__root have been delated, and before they've been set again (above).

This leads to an extremely difficult bug to diagnose when using multiprocessing.Queue to exchange OrderedDicts between multiple processes (because Queue uses a separate feeder thread to do the pickling).

The fix seems relatively easy -- use:

        inst_dict = vars(self).copy()
        del inst_dict['_OrderedDict__map'], inst_dict['_OrderedDict__root']

instead of the above four lines.

PS: This issue+fix may also apply to Python 3.x, although I haven't tested it there.
History
Date User Action Args
2011-04-19 08:28:24mjuricsetrecipients: + mjuric
2011-04-19 08:28:24mjuricsetmessageid: <1303201704.87.0.690807992306.issue11875@psf.upfronthosting.co.za>
2011-04-19 08:28:24mjuriclinkissue11875 messages
2011-04-19 08:28:23mjuriccreate