GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-96471: Add asyncio queue shutdown by EpicWink · Pull Request #104228 · python/cpython Conversation
|
|
@willingc ready for review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I assume the "on top of ..." part is obsolete, since that PR was closed without merging. I'll add @willingc as a reviewer per your request. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@EpicWink Could you merge main? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Done, but like #104750, we may want to modify the implementation of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Eh, @EpicWink, did you see the hubbub about the hanging test in your previous PR? The test was disabled because it kept hanging in CI on various platforms. Could you look into what's wrong with it? (At least the feature wasn't reverted.) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I did see the follow-on issue and pull-requests. Yves and I are working on fixing it (you can follow the changes here: main...EpicWink:cpython:fix-thread-queue-shutdown-test) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Awesome! (An acknowledgement that you were working on it would have lessened my stress. :-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Looking at this with an eye towards review, I realized that the threaded-queue implementation doesn't appear to match its documentation: It appears that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Now that the immediate-consume implementation of the threading queue shutdown has been accepted, I'm going to do the same here and for multiprocessing. I'll personally rewrite the tests to be more readable and obvious.
Laurie
…________________________________
From: Guido van Rossum ***@***.***>
Sent: Thursday, February 22, 2024 11:00:09 AM
To: python/cpython ***@***.***>
Cc: Laurie O ***@***.***>; Mention ***@***.***>
Subject: Re: [python/cpython] gh-96471: Add asyncio queue shutdown (PR #104228)
Looking at this with an eye towards review, I realized that the threaded-queue implementation doesn't appear to match its documentation: It appears that q.join() does not raise ShutDown when the queue is shutdown immediately. The tests don't seem to be testing for this either. (Come to think of it, the test never seems to take the except self.queue.ShutDown path -- if I put a breakpoint there it never gets hit during any of the tests. The test logic is pretty convoluted, which is my only excuse for not having caught this in the review of gh-104750<#104750>.)
—
Reply to this email directly, view it on GitHub<#104228 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AF72GRNKMPJRCRIJHOB4NUDYU2KBTAVCNFSM6AAAAAAXX3PWIGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJYGQ3TENZYGQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
And what about |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'll wait reviewing until you've rewritten shutdown, but here's one doc markup nit.
Also, please mark PRs that aren't ready for review as Draft.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
The behaviour should (and I intend to implement it to) be the same between the threading, multiprocessing and asyncio queues |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
By the way, should |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@gvanrossum please don't trust, have you seen
Oops, sorry. I forgot to hold off my most recent push
No, I think it was because I hadn't updated the implementation to match the new agreed-upon behaviour (this PR was in draft at that time anyway, so I don't think the label was needed).
I should probably add a comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # Setup queue with 2 items (1 retrieved), and a join() task | ||
| q = self.q_class() | ||
| loop = asyncio.get_running_loop() | ||
| q.put_nowait("data") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I suggest:
q.put_nowait("data1") q.put_nowait("data2")
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| q.put_nowait("data") | ||
| q.put_nowait("data") | ||
| join_task = loop.create_task(q.join()) | ||
| self.assertEqual(await q.get(), "data") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
and testing on "data1".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Except when q is an instance of LifoQueue, when the value should be "data2". Is it necessary to test queue ordering in the shutdown tests?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I forgot the LifoQueue class. Is this worth commenting on?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have implemented your suggestion, but I have not committed. I am considering it. I don't think it's necessary.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The test case (thus including LifoQueue) is implicit. A comment would be enough.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I have seen and commented |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yup! This version looks great. Let me know if you agree -- I've removed the DO-NOT-MERGE label, but I'll wait until you and @YvesDup are happy too.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I think it's good to go
I could do this, but I don't think it's worth revoking the PR's approval |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| All blocked callers of :meth:`~Queue.put` will be unblocked. If | ||
| *immediate* is true, also unblock callers of :meth:`~Queue.get` | ||
| and :meth:`~Queue.join`. | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry but I have a doubt, shouldn't this documentation block be rather:
All blocked callers of :meth:`~Queue.put` and :meth:`~Queue.get`
will be unblocked. If *immediate* is true, also unblock callers of
:meth:`~Queue.join`.
In event of change, the docstring of the shutdown method must be updated.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
join callers aren't necessarily even unblocked anyway, if consumers are processing any items. I should probably say that a task is marked as done for each item in the queue if immediate shutdown.
Also, I think the threading queue docs are the same.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
a task is marked as done for each item in the queue if immediate shutdown.
It's very precise, better.
Also, I think the threading queue docs are the same.
Yes, I commented here so as not to forget (see #117532 (comment)).
English is your native language, I think it'is best if you update documentations and docstrings.
Update: but I can create the follow-up PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've made a PR: #117621
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| All blocked callers of put() will be unblocked, and also get() | ||
| and join() if 'immediate'. | ||
| """ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Docstring to modify depending of agree/disagree on my first remark about `blocked callers'.
Changes could be:
All blocked callers of put() and get() will be unblocked, and
also join() if 'immediate
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * Add :meth:`asyncio.Queue.shutdown` (along with | ||
| :exc:`asyncio.QueueShutDown`) for queue termination. | ||
| (Contributed by Laurie Opperman in :gh:`104228`.) | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We've worked well together, I'd be nice if you'd mention me.
:-)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry for merging prematurely. @EpicWink Can you prepare a follow-up PR? I will merge it as soon as @YvesDup approves it. (Or, alternatively, @YvesDup can make a PR and I will merge when @EpicWink approves.) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@gvanrossum see #117621 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Duprat <[email protected]>
There was an error while loading. Please reload this page.
|
I'd like to add that the async def async_map[T, R]( func: Callable[[T], Awaitable[R]], iterable: AsyncIterable[T], *, limit: int, maxsize: int = -1, ) -> AsyncIterator[R]: if maxsize < 0: maxsize = limit arguments_queue = Queue[T](maxsize=maxsize) results_queue = Queue[R](maxsize=maxsize) async def drain(): async for argument in iterable: await arguments_queue.put(argument) arguments_queue.shutdown(immediate=False) async def worker(): while True: try: argument = await arguments_queue.get() except QueueShutDown: break await results_queue.put(await func(argument)) async def background(): async with asyncio.TaskGroup() as background_task_group: background_task_group.create_task(drain()) for _ in range(limit): background_task_group.create_task(worker()) results_queue.shutdown(immediate=False) async with asyncio.TaskGroup() as task_group: task_group.create_task(background()) while True: try: yield await results_queue.get() except QueueShutDown: break I believe this has a common issue that a lot of async generators do, in that if you don't consume the entire generator, it will still continue processing and end up with a lot of futures never awaited. I know there's some |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.