[issue32879] Race condition in multiprocessing Queue

Tim Peters report at bugs.python.org
Mon Feb 19 21:15:10 EST 2018


Tim Peters <tim at python.org> added the comment:

The docs could be clearer about this:  the argument to .put() is _not_ pickled at the time .put() is called.  The object is remembered (by reference, not by value), and a feeder thread pickles the value and puts the pickle on the queue when the feeder thread gets around to that.  So if the object is mutated in any way in between, it's not defined whether the pre- or post-mutation state is put on the queue (or, in some cases, even some partially mutated value).

To make it wholly deterministic you could, e.g., change the .put() to this:

        queue.put(data[:])

Or you could use a Manager().Queue() instead, which doesn't use a feeder thread.

----------
nosy: +tim.peters

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32879>
_______________________________________


More information about the Python-bugs-list mailing list