Repository navigation
gh-158880: Fix asyncio ps showing tasks from only one interpreter - #158900
deadlovelll wants to merge 6 commits into
Conversation
| loop.run_in_executor(pool, _asyncio_in_subinterpreter) | ||
| task = asyncio.create_task(main_worker(), name="main_worker") | ||
| self.addCleanup(task.cancel) | ||
| await asyncio.sleep(1) |
There was a problem hiding this comment.
asyncio.sleep feels like a flaky risk. What do you think about using busy_retry instead?
There was a problem hiding this comment.
Thanks! I fixed it
|
|
||
| // Process all threads | ||
| if (iterate_threads(self, process_thread_for_async_stack_trace, result) < 0) { | ||
| if (iterate_threads(self, self->interpreter_addr, |
There was a problem hiding this comment.
Unless I'm missing something, get_async_stack_trace() still has the same problem. Maybe it should be a follow-up, though.
There was a problem hiding this comment.
Yeah, it has the problem, i planned to open a separate issue for this to avoid "big-bang" pr
| return NULL; | ||
| } | ||
| if (refresh_generation_caches_for_interpreter(self, self->interpreter_addr) < 0) { | ||
| PyObject *seen = PySet_New(NULL); |
There was a problem hiding this comment.
This is just a list:
cpython/Modules/_remote_debugging/module.c
Lines 719 to 720 in 9028df3
cpython/Modules/_remote_debugging/module.c
Lines 884 to 885 in 9028df3
cpython/Modules/_remote_debugging/frames.c
Lines 459 to 462 in 182f323
Is there a reproducible race scenario where we'd see a cycle? (It was quiet easy to reproduce issues like ABA.)
There was a problem hiding this comment.
No, I couldn't reproduce a cycle. I thought the interpreter walk could loop
because of the previous PR, that's why I added the set. I agree with your suggestion and will rework it soon
There was a problem hiding this comment.
I rewrote the traverse
| for info in RemoteUnwinder( | ||
| os.getpid()).get_all_awaited_by() |
There was a problem hiding this comment.
One way to silence https://github.com/python/cpython/actions/runs/37499870518/job/112393935495#step:6:1023 is by wrapping this in except TRANSIENT_ERRORS:
Perhaps a better approach, similar to #158801
cpython/Lib/test/test_external_inspection.py
Lines 2440 to 2460 in 0e75a05
cpython/Lib/test/test_external_inspection.py
Lines 2469 to 2482 in 0e75a05
There was a problem hiding this comment.
I thought about how to stop the test flaking, so I decided to use queues in the test rather than silence exceptions. I ran the tests overnight many times, and there were no failures, ci here passed too
|
|
||
| // Process all threads | ||
| if (iterate_threads(self, process_thread_for_async_stack_trace, result) < 0) { | ||
| if (iterate_threads(self, self->interpreter_addr, |
| return -1; | ||
| } | ||
| } | ||
| return 0; |
There was a problem hiding this comment.
Edge case: 256 idle subinterpreters and one task in the main interpreter. get_all_awaited_by() would report no tasks.
New interpreters are prepended!
One way is to approach this is to raise RuntimeError if there are interpreters still left to visit.
Fix asyncio ps showing tasks from only one interpreter
For details see gh-158880