It is a simplified :class:`Queue` type, very close to a locked :class:`Pipe`.
+ .. method:: close()
+
+ Close the queue: release internal resources.
+
+ A queue must not be used anymore after it is closed. For example,
+ :meth:`get`, :meth:`put` and :meth:`empty` methods must no longer be
+ called.
+
+ .. versionadded:: 3.9
+
.. method:: empty()
Return ``True`` if the queue is empty, ``False`` otherwise.
if the given timeout for their constructor is zero to prevent the creation of
a non-blocking socket. (Contributed by Dong-hee Na in :issue:`39259`.)
+multiprocessing
+---------------
+
+The :class:`multiprocessing.SimpleQueue` class has a new
+:meth:`~multiprocessing.SimpleQueue.close` method to explicitly close the
+queue.
+(Contributed by Victor Stinner in :issue:`30966`.)
+
os
--
else:
self._wlock = ctx.Lock()
+ def close(self):
+ self._reader.close()
+ self._writer.close()
+
def empty(self):
return not self._poll()
proc.join()
+ def test_close(self):
+ queue = multiprocessing.SimpleQueue()
+ queue.close()
+ # closing a queue twice should not fail
+ queue.close()
+
+ # Test specific to CPython since it tests private attributes
+ @test.support.cpython_only
+ def test_closed(self):
+ queue = multiprocessing.SimpleQueue()
+ queue.close()
+ self.assertTrue(queue._reader.closed)
+ self.assertTrue(queue._writer.closed)
+
class TestPoolNotLeakOnFailure(unittest.TestCase):
--- /dev/null
+Add a new :meth:`~multiprocessing.SimpleQueue.close` method to the
+:class:`~multiprocessing.SimpleQueue` class to explicitly close the queue.