Skip to content

Remove UnboundedQueue #2922

Open
Open

Description

@A5rocks

This has been deprecated for a long time and I don't think that's been reversed. Just, it's used in the rest of trio so it would be a good idea to replace those.

Activity

  1. richardsheridan commented on Jan 17, 2024

    @richardsheridan
    Contributor
  2. arthur-tacca commented on Sep 17, 2026

    @arthur-tacca
    Member

    I stumbled across this while researching #3500. Trio currently has [the rule that]:

    there’s a very strict internal layering: the trio._core package is a fully self-contained implementation of the core scheduling/cancellation/IO handling logic, and then the other trio.* modules are implemented in terms of the API it exposes.

    #2925 violates by importing memory channels from outside of it. Actually even the existing ParkingLot in _core comes with a comment that says says its use in UnboundedQueue is the main reason its in _core. (It also mentions its theoretical role in ensuring fairness which is coupled to the task scheduling algorithm, but I suspect that wouldn't have been enough to justify its placement in _core by itself). I think, if anything, we should be aiming to replace the two usages of UnboundedQueue with a simpler alternative. Some options:

    • Keep UnboundedQueue but make it simpler (only one allowed recipient) (NJS suggested this at the end of this comment) so that at least the dependence on ParkingLot can be removed (for clarity: NJS never mentioned that bit).
    • Allow the caller to pass a memory channel (NJS mentioned this here as a way to allow different kevents to be sent to one channel) in which case _core only needs a protocol for it rather than importing the whole thing. monitor_kevent() now just waits forever since it no longer needs to return an iterable, and this gives an avenue for solving what to do with an exception raised by sending to a closed (or full) channel: it can be captured in process_events() and re-raised out of monitor_kevent.
    • My idea: instead of monitor_kevent returning an iterable (UnboundedQueue, memory channel, or whatever), or accepting a memory channel, it could accept a callback (admittedly it would usually be memory_channel_sender.send_nowait). Again, any exception from the callback would be captured and then raised out of monitor_kevent. This is more flexible and definitely avoids any dependency outside of _core but does mean user code is running at an unusual point in the event loop (it's not in any particular task, like guest mode, and it's KI protected).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions