We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 22136c9 commit bb5b529Copy full SHA for bb5b529
Lib/multiprocessing/queues.py
@@ -161,7 +161,7 @@ def _start_thread(self):
161
target=Queue._feed,
162
args=(self._buffer, self._notempty, self._send_bytes,
163
self._wlock, self._writer.close, self._ignore_epipe,
164
- self._on_queue_feeder_error),
+ self._on_queue_feeder_error, self._sem),
165
name='QueueFeederThread'
166
)
167
self._thread.daemon = True
@@ -203,7 +203,7 @@ def _finalize_close(buffer, notempty):
203
204
@staticmethod
205
def _feed(buffer, notempty, send_bytes, writelock, close, ignore_epipe,
206
- onerror):
+ onerror, queue_sem):
207
debug('starting thread to feed data to pipe')
208
nacquire = notempty.acquire
209
nrelease = notempty.release
@@ -255,6 +255,12 @@ def _feed(buffer, notempty, send_bytes, writelock, close, ignore_epipe,
255
info('error in queue thread: %s', e)
256
return
257
else:
258
+ # Since the object has not been sent in the queue, we need
259
+ # to decrease the size of the queue. The error acts as
260
+ # if the object had been silently removed from the queue
261
+ # and this step is necessary to have a properly working
262
+ # queue.
263
+ queue_sem.release()
264
onerror(e, obj)
265
266
Lib/test/_test_multiprocessing.py
@@ -1056,6 +1056,19 @@ def __reduce__(self):
1056
self.assertTrue(q.get(timeout=1.0))
1057
close_queue(q)
1058
1059
+ with test.support.captured_stderr():
1060
+ # bpo-33078: verify that the queue size is correctly handled
1061
+ # on errors.
1062
+ q = self.Queue(maxsize=1)
1063
+ q.put(NotSerializable())
1064
+ q.put(True)
1065
+ self.assertEqual(q.qsize(), 1)
1066
+ # bpo-30595: use a timeout of 1 second for slow buildbots
1067
+ self.assertTrue(q.get(timeout=1.0))
1068
+ # Check that the size of the queue is correct
1069
+ self.assertEqual(q.qsize(), 0)
1070
+ close_queue(q)
1071
+
1072
def test_queue_feeder_on_queue_feeder_error(self):
1073
# bpo-30006: verify feeder handles exceptions using the
1074
# _on_queue_feeder_error hook.
Misc/NEWS.d/next/Library/2018-03-15-07-38-00.bpo-33078.RmjUF5.rst
@@ -0,0 +1,2 @@
1
+Fix the size handling in multiprocessing.Queue when a pickling error
2
+occurs.