You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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).
Activity
richardsheridan commentedon Jan 17, 2024
xref: #40 (comment)
arthur-tacca commentedon Sep 17, 2026
I stumbled across this while researching #3500. Trio currently has [the rule that]:
#2925 violates by importing memory channels from outside of it. Actually even the existing
ParkingLotin_corecomes with a comment that says says its use inUnboundedQueueis 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_coreby itself). I think, if anything, we should be aiming to replace the two usages ofUnboundedQueuewith a simpler alternative. Some options:UnboundedQueuebut make it simpler (only one allowed recipient) (NJS suggested this at the end of this comment) so that at least the dependence onParkingLotcan be removed (for clarity: NJS never mentioned that bit)._coreonly 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 inprocess_events()and re-raised out ofmonitor_kevent.monitor_keventreturning an iterable (UnboundedQueue, memory channel, or whatever), or accepting a memory channel, it could accept a callback (admittedly it would usually bememory_channel_sender.send_nowait). Again, any exception from the callback would be captured and then raised out ofmonitor_kevent. This is more flexible and definitely avoids any dependency outside of_corebut 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).