summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/multiprocessing/queues.py8
-rw-r--r--Lib/test/_test_multiprocessing.py8
2 files changed, 14 insertions, 2 deletions
diff --git a/Lib/multiprocessing/queues.py b/Lib/multiprocessing/queues.py
index 88f7d26..d112db2 100644
--- a/Lib/multiprocessing/queues.py
+++ b/Lib/multiprocessing/queues.py
@@ -78,7 +78,8 @@ class Queue(object):
self._poll = self._reader.poll
def put(self, obj, block=True, timeout=None):
- assert not self._closed, "Queue {0!r} has been closed".format(self)
+ if self._closed:
+ raise ValueError(f"Queue {self!r} is closed")
if not self._sem.acquire(block, timeout):
raise Full
@@ -89,6 +90,8 @@ class Queue(object):
self._notempty.notify()
def get(self, block=True, timeout=None):
+ if self._closed:
+ raise ValueError(f"Queue {self!r} is closed")
if block and timeout is None:
with self._rlock:
res = self._recv_bytes()
@@ -298,7 +301,8 @@ class JoinableQueue(Queue):
self._cond, self._unfinished_tasks = state[-2:]
def put(self, obj, block=True, timeout=None):
- assert not self._closed, "Queue {0!r} is closed".format(self)
+ if self._closed:
+ raise ValueError(f"Queue {self!r} is closed")
if not self._sem.acquire(block, timeout):
raise Full
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 814aae8..dc59e9f 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -1114,6 +1114,14 @@ class _TestQueue(BaseTestCase):
# Assert that the serialization and the hook have been called correctly
self.assertTrue(not_serializable_obj.reduce_was_called)
self.assertTrue(not_serializable_obj.on_queue_feeder_error_was_called)
+
+ def test_closed_queue_put_get_exceptions(self):
+ for q in multiprocessing.Queue(), multiprocessing.JoinableQueue():
+ q.close()
+ with self.assertRaisesRegex(ValueError, 'is closed'):
+ q.put('foo')
+ with self.assertRaisesRegex(ValueError, 'is closed'):
+ q.get()
#
#
#