8000 gh-76785: More Fixes for test.support.interpreters by ericsnowcurrently · Pull Request #113012 · python/cpython · GitHub
[go: up one dir, main page]

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 the exception types to the extension module.
  • Loading branch information
ericsnowcurrently committed Dec 12, 2023
commit 8bb4290af564b4c5a5f9c43412b6558c9b3f8d1e
91 changes: 17 additions & 74 deletions Lib/test/support/interpreters/queues.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

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


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
elif exc.errcode is _queues.ERR_QUEUE_FULL:
exc.__class__ = QueueFull


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

Expand Down Expand Up @@ -77,20 +50,14 @@ def __new__(cls, id, /):
self = super().__new__(cls)
self._id = id
_known_queues[id] = self
try:
_queues.bind(id)
except QueueError as exc:
_apply_subclass(exc)
raise # re-raise
_queues.bind(id)
return self

def __del__(self):
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
except QueueNotFoundError:
pass
try:
del _known_queues[self._id]
except KeyError:
Expand Down Expand Up @@ -121,11 +88,7 @@ def full(self):
return _queues.is_full(self._id)

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

def put(self, obj, timeout=None, *,
_delay=10 / 1000, # 10 milliseconds
Expand All @@ -142,26 +105,17 @@ def put(self, obj, timeout=None, *,
while True:
try:
_queues.put(self._id, obj)
except QueueError as exc:
if exc.errcode == _queues.ERR_QUEUE_FULL:
if timeout is None or time.time() < end:
time.sleep(_delay)
continue
_apply_subclass(exc)
raise # re-raise
except QueueFull:
if timeout is not None and time.time() >= end:
raise # re-raise
time.sleep(_delay)
else:
break

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

def get(self, timeout=None, *,
_sentinel=object(),
_delay=10 / 1000, # 10 milliseconds
):
"""Return the next object from the queue.
Expand All @@ -175,31 +129,20 @@ def get(self, timeout=None, *,
end = time.time() + timeout
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
return _queues.get(self._id)
except QueueEmpty:
if timeout is not None and time.time() >= end:
raise # re-raise
time.sleep(_delay)
return obj

def get_nowait(self, *, _sentinel=object()):
def get_nowait(self):
"""Return the next object from the channel.

If the queue is empty then raise QueueEmpty. Otherwise this
is the same as get().
"""
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
return _queues.get(self._id)


_queues._register_queue_type(Queue)
Loading
0