https://github.com/python/cpython/commit/074a2cd400dc428c520c577df01c7b10550c69fc commit: 074a2cd400dc428c520c577df01c7b10550c69fc branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: hugovk <[email protected]> date: 2026-09-21T11:54:11+03:00 summary:
[3.15] gh-157788: Fix python -m asyncio ps failing on long task names (GH-157790) (#157826) Co-authored-by: Timofei Ivankov <[email protected]> files: A Misc/NEWS.d/next/Library/2026-09-19-14-10-18.gh-issue-157788.v70Lxd.rst M Lib/test/test_external_inspection.py M Modules/_remote_debugging/object_reading.c diff --git a/Lib/test/test_external_inspection.py b/Lib/test/test_external_inspection.py index 910fe96d5e7d81e..1fed0f9175e8e10 100644 --- a/Lib/test/test_external_inspection.py +++ b/Lib/test/test_external_inspection.py @@ -1,3 +1,4 @@ +import asyncio import unittest import os import textwrap @@ -440,6 +441,22 @@ def _extract_coroutine_stacks_lineno_only(self, stack_trace): @requires_remote_subprocess_debugging() class TestSelfStackTrace(RemoteInspectionTestBase): + @skip_if_not_supported + def test_long_task_name_is_truncated(self): + # gh-157788 + async def main(): + asyncio.create_task(asyncio.sleep(10_000), name="x" * 300) + await asyncio.sleep(0) + return [ + task.task_name + for info in RemoteUnwinder(os.getpid()).get_all_awaited_by() + for task in info.awaited_by + ] + + names = asyncio.run(main()) + self.assertIn("Task-1", names) + self.assertEqual([len(n) for n in names if n.startswith("x")], [255]) + @skip_if_not_supported @unittest.skipIf( sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED, diff --git a/Misc/NEWS.d/next/Library/2026-09-19-14-10-18.gh-issue-157788.v70Lxd.rst b/Misc/NEWS.d/next/Library/2026-09-19-14-10-18.gh-issue-157788.v70Lxd.rst new file mode 100644 index 000000000000000..641ca0a82a0915e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-09-19-14-10-18.gh-issue-157788.v70Lxd.rst @@ -0,0 +1,2 @@ +Fix ``python -m asyncio ps`` failing on a process that has a task with a +name longer than 255 characters. diff --git a/Modules/_remote_debugging/object_reading.c b/Modules/_remote_debugging/object_reading.c index 1cea96a2151fcc6..56d9f80a80fd0f5 100644 --- a/Modules/_remote_debugging/object_reading.c +++ b/Modules/_remote_debugging/object_reading.c @@ -64,12 +64,16 @@ read_py_str( } Py_ssize_t len = GET_MEMBER(Py_ssize_t, unicode_obj, unwinder->debug_offsets.unicode_object.length); - if (len < 0 || len > max_len) { + if (len < 0) { PyErr_Format(PyExc_RuntimeError, "Invalid string length (%zd) at 0x%lx", len, address); set_exception_cause(unwinder, PyExc_RuntimeError, "Invalid string length in remote Unicode object"); return NULL; } + if (len > max_len) { + // gh-157788: a long name must not fail the whole read + len = max_len; + } // Inspect state to pick the right data offset and character width. // We rely on the remote process sharing this Python version's _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
