| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
* Include docs
* Include raised exception in docstrings * Handle queue shutdown in task_done and join * Factor out queue-state checks and updates to methods * Logic fixes in qsize, get and shutdown * Don't set unfinished_tasks to 0 on immediate shutdown * Updated tests * Document feature added in 3.13
There was a problem hiding this comment.
Great progress. I mostly have some markup nits. But the tests seem to hang. Or was I just impatient?
Sorry, something went wrong.
|
Yeah, the test is definitely hanging for me. Have you figured that out yet? |
Sorry, something went wrong.
|
I'd also recommend a merge. :-) |
Sorry, something went wrong.
…tdown-immediate-consume
@gvanrossum It's intermittently hanging in the test test_shutdown_immediate_put_join. q.join is blocking, after shutting down the queue, because unfinished_tasks becomes -1 (when zero is required). This is because the test calls task_done before taking items from the queue, but the implementation of shutdown() reduces unfinished_tasks by the number of items in the queue. I think the solution is to simply ensure unfinished_tasks doesn't go negative. I don't set it straight to zero because there may still be queue consumer who will successfully complete their task and call task_done, but they will get a ValueError if unfinished_tasks was immediately set to zero. There is a problem here however if some consumers still call task_done without getting items from the queue. Perhaps it's simpler to set unfinished_tasks to zero, then skip the ValueError raise if the queue is shut down. Edit: I just noticed that this pull request's description says that task_done should raise ValueError on a shut down queue. Hmmm. It's also intermittently hanging in the test test_shutdown_put_join, simply because of a logic error: 2 items are put on the queue (sometimes), then it's shut down, then one task is marked as done, then the queue is waited for (aka joined on). If only one item was put on the queue, then the test simply fails during assertion. Solution here (which fixes the assertion for test_shutdown_immediate_put_join as well) is to shut down the queue before running the put-then-join. Edit: and of course now it's failing only in Windows (CI only succeeds because it re-runs test_queue) |
Sorry, something went wrong.
Also shut down before put-join in shutdown-put-join tests. Also remove indent
There was a problem hiding this comment.
LG, assuming you believe the test is stable. I have one nit, let me know how you feel about that.
Oh, one more thing. If you feel like writing documentation, could you update Doc/whatsnew/3.13.rst? There's a section about modified modules. A few lines there will go a long way.
Sorry, something went wrong.
Test is not stable, as test_shutdown_all_methods_in_many_threads (and the corresponding immediate version) hangs intermittently in Windows. It also fails consistently when adding debugging print-statements on my machine. I'm investigating |
Sorry, something went wrong.
There was a problem hiding this comment.
Excellent! All that remains is merging it (which I will take care of), closing the alternative PR for queue.py, and then we can have another look at the asyncio and multiprocessing queues. (For the latter we still need to find a reviewer.)
Sorry, something went wrong.
|
@EpicWink Sorry, it looks like we have to revert this until the Windows free-threading hang has been resolved. (Although it's possible that you've uncovered a Windows-related bug in free-threading, which is a developing feature.) |
Sorry, something went wrong.
|
FWIW, having had only a quick look at the failing test, is it possible that it relies on timeouts too much? I see that there's a 0.1 msec delay that is used for sleeping, and _read_msg_thread() makes some non-blocking get() calls, ignoring Empty exceptions. Could there be a scenario (especially when running without GIL) where different threads run in a different order than you anticipated, and it simply doesn't read enough queue items, so the join() hangs forever? |
Sorry, something went wrong.
Co-authored-by: Duprat <yduprat@gmail.com>
|
From #104228 (comment): it looks like Queue.join() never raises ShutDown, contradicting the docs. |
Sorry, something went wrong.
|
Maybe I'm waking up a little too late, but despite having worked on the development 1 year ago, I have the impression that functionalities are missing in this merged PR. In the initial version of the feature (#104225), the basic shutdown just forbade put operations, also released all threads blocked in put. On the other hand, it left get, join and task_done operations possible. The immediate shutdown prohibited all possible previous operations and had to release all threads blocked in get, and join. And the queue was purged. Currently, in the following methods (put, get, join and task_done), there is no specific behavior depending on the type of the shutdown. It's not even noted in an attribute. I don't want to hurt anyone's feelings, but I think this PR needs to be reworked (including documentation). PS: initial comment was done at the bad PR. Sorry |
Sorry, something went wrong.
@YvesDup see comment in the issue: #96471 (comment) Basically, the goal is to have waiters (callers of queue methods) not be blocked on a queue which has been shut-down. Making the shutdown immediate simply means gets won't take anything more from the queue (and instead except). There is a problem with this PR though, in that q.task_done() and q.join() are documented as raising ShutDown when they don't; see #115838 for the fix for that. |
Sorry, something went wrong.
|
@EpicWink , thank you for this explanation. I ve missed that :-( |
Sorry, something went wrong.
|
FYI, I fixed the failling test in _read_msg_thread() method. Loop was infinite, I insert a break on queue.Shutdow exception. .... (and I removed all time.sleep()) |
Sorry, something went wrong.
Where can we see this? |
Sorry, something went wrong.
https://github.com/YvesDup/cpython/blob/Threading-queue-shutdown-test-failed/Lib/test/test_queue.py#L350 |
Sorry, something went wrong.
|
Thanks, I'll wait for the pull request. |
Sorry, something went wrong.
PR is ready on this issue (#115940). Sorry if I didn't understand that you wait for a PR linked to this one. Please let me know if I have to change. |
Sorry, something went wrong.
There are related because there are both about on the same issue. But #115898 is only a draft. |
Sorry, something went wrong.
|
I'll review the new PR fixing the test today. My PR is another attempt, but unfinished. Perhaps in the future it can be added as another test. Edit: reviewed! |
Sorry, something went wrong.
Thank for the review. |
Sorry, something went wrong.
…ython#117532) (This is a small tweak of the original pythongh-104750 which added shutdown.)
| Back | FazBrowse Home | New Git URL |
Alternate implementation of #104225, where all queue items are consumed immediately in Queue.shutdown when immediate=True is passed (see the comparison for what's changed).
This PR includes and modified changes from #104225.
📚 Documentation preview 📚: https://cpython-previews--104750.org.readthedocs.build/