Skip to content
Open
Changes from all commits
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
31 changes: 31 additions & 0 deletions src/trio/_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ def __init__(self, max_buffer_size: int | float) -> None: # noqa: PYI041

@attrs.frozen
class MemoryChannelStatistics:
"""Statistics about a memory channel.

Attributes:
current_buffer_used: The number of items currently stored in the
channel buffer.
max_buffer_size: The maximum number of items allowed in the buffer,
as passed to :func:`open_memory_channel`.
open_send_channels: The number of open :class:`MemorySendChannel`
endpoints pointing to this channel.
open_receive_channels: The number of open :class:`MemoryReceiveChannel`
endpoints pointing to this channel.
tasks_waiting_send: The number of tasks blocked in ``send`` on this
channel (summing over all clones).
tasks_waiting_receive: The number of tasks blocked in ``receive`` on
this channel (summing over all clones).
"""

current_buffer_used: int
max_buffer_size: int | float
open_send_channels: int
Expand Down Expand Up @@ -152,6 +169,13 @@ def statistics(self) -> MemoryChannelStatistics:
@final
@attrs.define(eq=False, repr=False, slots=False)
class MemorySendChannel(SendChannel[SendType], metaclass=NoPublicConstructor):
"""The sending end of a memory channel.

Memory channels are created using :func:`open_memory_channel`, which
returns a pair of (:class:`MemorySendChannel`, :class:`MemoryReceiveChannel`).
See :func:`open_memory_channel` for full documentation.
"""

_state: MemoryChannelState[SendType]
_closed: bool = False
# This is just the tasks waiting on *this* object. As compared to
Expand Down Expand Up @@ -300,6 +324,13 @@ async def aclose(self) -> None:
@final
@attrs.define(eq=False, repr=False, slots=False)
class MemoryReceiveChannel(ReceiveChannel[ReceiveType], metaclass=NoPublicConstructor):
"""The receiving end of a memory channel.

Memory channels are created using :func:`open_memory_channel`, which
returns a pair of (:class:`MemorySendChannel`, :class:`MemoryReceiveChannel`).
See :func:`open_memory_channel` for full documentation.
"""

_state: MemoryChannelState[ReceiveType]
_closed: bool = False
_tasks: set[trio._core._run.Task] = attrs.Factory(set)
Expand Down
Loading