Content-Length: 393075 | pFad | http://github.com/python/cpython/pull/113012/commits/e4d18ffdcce250cd66187be4a74b94f0ae0a2084

D8 gh-76785: More Fixes for test.support.interpreters by ericsnowcurrently · Pull Request #113012 · python/cpython · GitHub
Skip to content

gh-76785: More Fixes for test.support.interpreters #113012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move most exception types to the interpreters module.
  • Loading branch information
ericsnowcurrently committed Dec 12, 2023
commit e4d18ffdcce250cd66187be4a74b94f0ae0a2084
88 changes: 65 additions & 23 deletions Lib/test/support/interpreters/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# aliases:
from _xxinterpqueues import (
QueueError, QueueNotFoundError,
QueueError,
)

__all__ = [
Expand All @@ -17,6 +17,31 @@
]


class QueueNotFoundError(QueueError):
"""Raised any time a requrested queue is missing."""


class QueueEmpty(QueueError, queue.Empty):
"""Raised from get_nowait() when the queue is empty.

It is also raised from get() if it times out.
"""


class QueueFull(QueueError, queue.Full):
"""Raised from put_nowait() when the queue is full.

It is also raised from put() if it times out.
"""


def _apply_subclass(exc):
if exc.errcode is _queues.ERR_QUEUE_NOT_FOUND:
exc.__class__ = QueueNotFoundError
elif exc.errcode is _queues.ERR_QUEUE_EMPTY:
exc.__class__ = QueueEmpty


def create(maxsize=0):
"""Return a new cross-interpreter queue.

Expand All @@ -33,19 +58,6 @@ def list_all():
for qid in _queues.list_all()]


class QueueEmpty(QueueError, queue.Empty):
"""Raised from get_nowait() when the queue is empty.

It is also raised from get() if it times out.
"""


class QueueFull(QueueError, queue.Full):
"""Raised from put_nowait() when the queue is full.

It is also raised from put() if it times out.
"""


_known_queues = weakref.WeakValueDictionary()

Expand Down Expand Up @@ -78,14 +90,23 @@ def __new__(cls, id, /, *, _maxsize=None):
self._id = id
self._maxsize = maxsize
_known_queues[id] = self
_queues.bind(id)
try:
_queues.bind(id)
except QueueError as exc:
_apply_subclass(exc)
raise # re-raise
else:
if _maxsize is not None:
raise Exception('maxsize may not be changed')
return self

def __del__(self):
_queues.release(self._id)
try:
_queues.release(self._id)
except QueueError as exc:
if exc.errcode is not _queues.ERR_QUEUE_NOT_FOUND:
_apply_subclass(exc)
raise # re-raise
try:
del _known_queues[self._id]
except KeyError:
Expand Down Expand Up @@ -114,15 +135,27 @@ def full(self):
return self.qsize() >= self._maxsize

def qsize(self):
return _queues.get_count(self._id)
try:
return _queues.get_count(self._id)
except QueueError as exc:
_apply_subclass(exc)
raise # re-raise

def put(self, obj, timeout=None):
# XXX block if full
_queues.put(self._id, obj)
try:
_queues.put(self._id, obj)
except QueueError as exc:
_apply_subclass(exc)
raise # re-raise

def put_nowait(self, obj):
# XXX raise QueueFull if full
return _queues.put(self._id, obj)
try:
return _queues.put(self._id, obj)
except QueueError as exc:
_apply_subclass(exc)
raise # re-raise

def get(self, timeout=None, *,
_sentinel=object(),
Expand All @@ -137,12 +170,17 @@ def get(self, timeout=None, *,
if timeout < 0:
raise ValueError(f'timeout value must be non-negative')
end = time.time() + timeout
obj = _queues.get(self._id, _sentinel)
while obj is _sentinel:
while True:
try:
obj = _queues.get(self._id, _sentinel)
except QueueError as exc:
_apply_subclass(exc)
raise # re-raise
if obj is not _sentinel:
break
time.sleep(_delay)
if timeout is not None and time.time() >= end:
raise QueueEmpty
obj = _queues.get(self._id, _sentinel)
return obj

def get_nowait(self, *, _sentinel=object()):
Expand All @@ -151,7 +189,11 @@ def get_nowait(self, *, _sentinel=object()):
If the queue is empty then raise QueueEmpty. Otherwise this
is the same as get().
"""
obj = _queues.get(self._id, _sentinel)
try:
obj = _queues.get(self._id, _sentinel)
except QueueError as exc:
_apply_subclass(exc)
raise # re-raise
if obj is _sentinel:
raise QueueEmpty
return obj
Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/pull/113012/commits/e4d18ffdcce250cd66187be4a74b94f0ae0a2084

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy