New GitHub issue #119154 from Zac-HD:<br>
<hr>
<pre>
# Feature or enhancement
### Proposal:
Over the last few years, Trio and AnyIO users have proven out several design patterns using channels as async iterables. For example, having a context manager yield an async iterable avoids the motivating problems of both PEP-533 and PEP-789.
An `asyncio.Queue` is almost identical to a channel-pair, especially with the `.shutdown()` method added in Python 3.13. I therefore propose that we add an `.__aiter__` method, to more support such design patterns without subclassing or a generator helper function.
```python
async def __aiter__(self):
try:
while True:
yield await self.get()
except asyncio.QueueShutDown:
raise StopAsyncIteration from None
```
### Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
### Links to previous discussion of this feature:
https://github.com/python/peps/pull/3782#pullrequestreview-2059307313 suggested that `queue.Queue` could also be iterable. If we're extending this to synchronous classes I'd also include `multiprocessing.Queue` and `multiprocessing.SimpleQueue`. I'd omit `multiprocessing.connection.Connection`, due to the byte-level send/recv methods, and `queue.SimpleQueue` because without a `.close()` or `.shutdown()` method there's no clean way to shut down.
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/119154">View on GitHub</a>
<p>Labels: type-feature</p>
<p>Assignee: </p>