Skip to content

Commit 6d23a83

Browse files
committed
Remove deprecated unbounded queue
1 parent d1cc062 commit 6d23a83

12 files changed

+49
-370
lines changed

check.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

33
set -ex
4+
set -o pipefail
45

56
ON_GITHUB_CI=true
67
EXIT_STATUS=0
@@ -55,16 +56,15 @@ MYPY=0
5556
echo "::group::Mypy"
5657
# Cleanup previous runs.
5758
rm -f mypy_annotate.dat
58-
# Pipefail makes these pipelines fail if mypy does, even if mypy_annotate.py succeeds.
59-
set -o pipefail
59+
6060
mypy --show-error-end --platform linux | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \
6161
|| { echo "* Mypy (Linux) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; }
6262
# Darwin tests FreeBSD too
6363
mypy --show-error-end --platform darwin | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \
6464
|| { echo "* Mypy (Mac) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; }
6565
mypy --show-error-end --platform win32 | python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \
6666
|| { echo "* Mypy (Windows) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; }
67-
set +o pipefail
67+
6868
# Re-display errors using Github's syntax, read out of mypy_annotate.dat
6969
python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat
7070
# Then discard.

src/trio/_core/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
temporarily_detach_coroutine_object,
6464
wait_task_rescheduled,
6565
)
66-
from ._unbounded_queue import UnboundedQueue, UnboundedQueueStatistics
6766

6867
# Windows imports
6968
if sys.platform == "win32":

src/trio/_core/_generated_io_kqueue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
if TYPE_CHECKING:
1212
import select
1313

14-
from .. import _core
14+
from .. import _channel
1515
from .._file_io import _HasFileNo
1616
from ._traps import Abort, RaiseCancelT
1717
import sys
@@ -43,7 +43,7 @@ def current_kqueue() -> select.kqueue:
4343

4444
def monitor_kevent(
4545
ident: int, filter: int
46-
) -> ContextManager[_core.UnboundedQueue[select.kevent]]:
46+
) -> ContextManager[_channel.MemoryRecvChannel[select.kevent]]:
4747
"""TODO: these are implemented, but are currently more of a sketch than
4848
anything real. See `#26
4949
<https://github.com/python-trio/trio/issues/26>`__.

src/trio/_core/_generated_io_windows.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
if TYPE_CHECKING:
1212
from typing_extensions import Buffer
1313

14+
from .._channel import MemoryReceiveChannel
1415
from .._file_io import _HasFileNo
15-
from ._unbounded_queue import UnboundedQueue
1616
from ._windows_cffi import CData, Handle
1717
import sys
1818

@@ -189,7 +189,9 @@ def current_iocp() -> int:
189189
raise RuntimeError("must be called from async context") from None
190190

191191

192-
def monitor_completion_key() -> ContextManager[tuple[int, UnboundedQueue[object]]]:
192+
def monitor_completion_key() -> (
193+
ContextManager[tuple[int, MemoryReceiveChannel[object]]]
194+
):
193195
"""TODO: these are implemented, but are currently more of a sketch than
194196
anything real. See `#26
195197
<https://github.com/python-trio/trio/issues/26>`__ and `#52

src/trio/_core/_io_kqueue.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import errno
4+
import math
45
import select
56
import sys
67
from contextlib import contextmanager
@@ -9,14 +10,14 @@
910
import attr
1011
import outcome
1112

12-
from .. import _core
13+
from .. import _channel, _core
1314
from ._run import _public
1415
from ._wakeup_socketpair import WakeupSocketpair
1516

1617
if TYPE_CHECKING:
1718
from typing_extensions import TypeAlias
1819

19-
from .._core import Abort, RaiseCancelT, Task, UnboundedQueue
20+
from .._core import Abort, RaiseCancelT, Task
2021
from .._file_io import _HasFileNo
2122

2223
assert not TYPE_CHECKING or (sys.platform != "linux" and sys.platform != "win32")
@@ -34,10 +35,9 @@ class _KqueueStatistics:
3435
@attr.s(slots=True, eq=False)
3536
class KqueueIOManager:
3637
_kqueue: select.kqueue = attr.ib(factory=select.kqueue)
37-
# {(ident, filter): Task or UnboundedQueue}
38-
_registered: dict[tuple[int, int], Task | UnboundedQueue[select.kevent]] = attr.ib(
39-
factory=dict
40-
)
38+
_registered: dict[
39+
tuple[int, int], Task | _channel.MemorySendChannel[select.kevent]
40+
] = attr.ib(factory=dict)
4141
_force_wakeup: WakeupSocketpair = attr.ib(factory=WakeupSocketpair)
4242
_force_wakeup_fd: int | None = attr.ib(default=None)
4343

@@ -94,7 +94,7 @@ def process_events(self, events: EventResult) -> None:
9494
if isinstance(receiver, _core.Task):
9595
_core.reschedule(receiver, outcome.Value(event))
9696
else:
97-
receiver.put_nowait(event)
97+
receiver.send_nowait(event)
9898

9999
# kevent registration is complicated -- e.g. aio submission can
100100
# implicitly perform a EV_ADD, and EVFILT_PROC with NOTE_TRACK will
@@ -119,7 +119,7 @@ def current_kqueue(self) -> select.kqueue:
119119
@_public
120120
def monitor_kevent(
121121
self, ident: int, filter: int
122-
) -> Iterator[_core.UnboundedQueue[select.kevent]]:
122+
) -> Iterator[_channel.MemoryRecvChannel[select.kevent]]:
123123
"""TODO: these are implemented, but are currently more of a sketch than
124124
anything real. See `#26
125125
<https://github.com/python-trio/trio/issues/26>`__.
@@ -129,11 +129,12 @@ def monitor_kevent(
129129
raise _core.BusyResourceError(
130130
"attempt to register multiple listeners for same ident/filter pair"
131131
)
132-
q = _core.UnboundedQueue[select.kevent]()
133-
self._registered[key] = q
132+
send, recv = _channel.open_memory_channel[select.kevent](math.inf)
133+
self._registered[key] = send
134134
try:
135-
yield q
135+
yield recv
136136
finally:
137+
send.close()
137138
del self._registered[key]
138139

139140
@_public
@@ -274,8 +275,5 @@ def notify_closing(self, fd: int | _HasFileNo) -> None:
274275
_core.reschedule(receiver, outcome.Error(exc))
275276
del self._registered[key]
276277
else:
277-
# XX this is an interesting example of a case where being able
278-
# to close a queue would be useful...
279-
raise NotImplementedError(
280-
"can't close an fd that monitor_kevent is using"
281-
)
278+
receiver.close()
279+
del self._registered[key]

src/trio/_core/_io_windows.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import enum
44
import itertools
5+
import math
56
import socket
67
import sys
78
from contextlib import contextmanager
@@ -43,9 +44,9 @@
4344
if TYPE_CHECKING:
4445
from typing_extensions import Buffer, TypeAlias
4546

47+
from .._channel import MemoryReceiveChannel, MemorySendChannel
4648
from .._file_io import _HasFileNo
4749
from ._traps import Abort, RaiseCancelT
48-
from ._unbounded_queue import UnboundedQueue
4950

5051
EventResult: TypeAlias = int
5152
T = TypeVar("T")
@@ -435,7 +436,7 @@ def __init__(self) -> None:
435436
self._overlapped_waiters: dict[CData, _core.Task] = {}
436437
self._posted_too_late_to_cancel: set[CData] = set()
437438

438-
self._completion_key_queues: dict[int, UnboundedQueue[object]] = {}
439+
self._completion_key_queues: dict[int, MemorySendChannel[object]] = {}
439440
self._completion_key_counter = itertools.count(CKeys.USER_DEFINED)
440441

441442
with socket.socket() as s:
@@ -610,7 +611,7 @@ def process_events(self, received: EventResult) -> None:
610611
info = CompletionKeyEventInfo(
611612
lpOverlapped=overlapped, dwNumberOfBytesTransferred=transferred
612613
)
613-
queue.put_nowait(info)
614+
queue.send_nowait(info)
614615

615616
def _register_with_iocp(self, handle_: int | CData, completion_key: int) -> None:
616617
handle = _handle(handle_)
@@ -981,16 +982,21 @@ def current_iocp(self) -> int:
981982

982983
@contextmanager
983984
@_public
984-
def monitor_completion_key(self) -> Iterator[tuple[int, UnboundedQueue[object]]]:
985+
def monitor_completion_key(
986+
self,
987+
) -> Iterator[tuple[int, MemoryReceiveChannel[object]]]:
985988
"""TODO: these are implemented, but are currently more of a sketch than
986989
anything real. See `#26
987990
<https://github.com/python-trio/trio/issues/26>`__ and `#52
988991
<https://github.com/python-trio/trio/issues/52>`__.
989992
"""
993+
from .._channel import open_memory_channel
994+
990995
key = next(self._completion_key_counter)
991-
queue = _core.UnboundedQueue[object]()
992-
self._completion_key_queues[key] = queue
996+
send, recv = open_memory_channel[object](math.inf)
997+
self._completion_key_queues[key] = send
993998
try:
994-
yield (key, queue)
999+
yield (key, recv)
9951000
finally:
1001+
send.close()
9961002
del self._completion_key_queues[key]

src/trio/_core/_parking_lot.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
# theirs and our tasks are lighter, so for us #objects is smaller and #tasks
2222
# is larger.
2323
#
24-
# This is in the core because for two reasons. First, it's used by
25-
# UnboundedQueue, and UnboundedQueue is used for a number of things in the
26-
# core. And second, it's responsible for providing fairness to all of our
27-
# high-level synchronization primitives (locks, queues, etc.). For now with
28-
# our FIFO scheduler this is relatively trivial (it's just a FIFO waitqueue),
29-
# but in the future we ever start support task priorities or fair scheduling
24+
# This is in the core because it's responsible for providing fairness to all
25+
# of our high-level synchronization primitives (locks, queues, etc.). For now
26+
# with our FIFO scheduler this is relatively trivial (it's just a FIFO
27+
# waitqueue), but in the future we ever start support task priorities or fair
28+
# scheduling
3029
#
3130
# https://github.com/python-trio/trio/issues/32
3231
#

src/trio/_core/_tests/test_unbounded_queue.py

Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
 (0)