Message134023
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. |
|
Date |
User |
Action |
Args |
2011-04-19 08:28:24 | mjuric | set | recipients:
+ mjuric |
2011-04-19 08:28:24 | mjuric | set | messageid: <1303201704.87.0.690807992306.issue11875@psf.upfronthosting.co.za> |
2011-04-19 08:28:24 | mjuric | link | issue11875 messages |
2011-04-19 08:28:23 | mjuric | create | |
|