https://github.com/python/cpython/commit/04b7fff7d6fb3c500ea73b91521857e10035b45b
commit: 04b7fff7d6fb3c500ea73b91521857e10035b45b
branch: 3.14
author: Timofei Ivankov <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-09-21T16:22:08+05:30
summary:
[3.14] gh-157788: Fix python -m asyncio ps failing on long task names (#157843)
gh-157788: Fix python -m asyncio ps failing on long task names
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_module.c
diff --git a/Lib/test/test_external_inspection.py
b/Lib/test/test_external_inspection.py
index 08779bdb0081397..957c4b91acbfcd1 100644
--- a/Lib/test/test_external_inspection.py
+++ b/Lib/test/test_external_inspection.py
@@ -1,4 +1,5 @@
import unittest
+import asyncio
import os
import textwrap
import importlib
@@ -66,6 +67,22 @@ def get_all_awaited_by(pid):
class TestGetStackTrace(unittest.TestCase):
maxDiff = None
+ @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_module.c
b/Modules/_remote_debugging_module.c
index 4fe94d439242319..b51ed4dcb7951c5 100644
--- a/Modules/_remote_debugging_module.c
+++ b/Modules/_remote_debugging_module.c
@@ -1109,12 +1109,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;
+ }
buf = (char *)PyMem_RawMalloc(len+1);
if (buf == NULL) {
_______________________________________________
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]