mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-22872: multiprocessing.Queue's put() and get() now raise ValueError if the queue is closed. (GH-9010)
Previously, put() and get() would raise AssertionError and OSError, respectively.
This commit is contained in:
parent
e385d0661e
commit
0461704060
4 changed files with 26 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue