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

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

This object is returned by the ``statistics()`` method on
:class:`MemorySendChannel` and :class:`MemoryReceiveChannel`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO not necessary to have a backref like this here.


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 +172,15 @@ 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.

This implements the :class:`~trio.abc.SendChannel` interface.
"""

_state: MemoryChannelState[SendType]
_closed: bool = False
# This is just the tasks waiting on *this* object. As compared to
Expand Down Expand Up @@ -300,6 +329,15 @@ 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.

This implements the :class:`~trio.abc.ReceiveChannel` interface.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh I don't think this is necessary. Do we do this elsewhere?

"""

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