]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-152434: Block --async-aware with --binary (GH-152444) (#152446)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 27 Jun 2026 17:24:53 +0000 (19:24 +0200)
committerGitHub <noreply@github.com>
Sat, 27 Jun 2026 17:24:53 +0000 (17:24 +0000)
gh-152434: Block --async-aware with --binary (GH-152444)

The binary writer does not currently handle AwaitedInfo samples and
crashes when running in --async-aware mode.
(cherry picked from commit 876c06cab9e824747d708a031c6b81b1f8a4f8dc)

Co-authored-by: László Kiss Kollár <kiss.kollar.laszlo@gmail.com>
Lib/profiling/sampling/cli.py
Lib/test/test_profiling/test_sampling_profiler/test_cli.py

index a5d9573ae6b6dddc0f8dddf3217c9613f6bec759..0330c15c014545ceef2f912a824c4bf867136098 100644 (file)
@@ -875,13 +875,15 @@ def _validate_args(args, parser):
         if hasattr(args, 'live') and args.live:
             parser.error("--subprocesses is incompatible with --live mode.")
 
-    # Async-aware mode is incompatible with --native, --no-gc, --mode, and --all-threads
+    # Async-aware mode is incompatible with options that need thread data.
     if getattr(args, 'async_aware', False):
         issues = []
         if getattr(args, 'native', False):
             issues.append("--native")
         if not getattr(args, 'gc', True):
             issues.append("--no-gc")
+        if getattr(args, 'format', None) == "binary":
+            issues.append("--binary")
         if hasattr(args, 'mode') and args.mode != "wall":
             issues.append(f"--mode={args.mode}")
         if hasattr(args, 'all_threads') and args.all_threads:
index 9c0734ac804e1bc4becb1fce4edc318e3c2b87e3..0181095ca21e37580080dd489a06fa963bfd976b 100644 (file)
@@ -866,6 +866,23 @@ class TestSampleProfilerCLI(unittest.TestCase):
         self.assertIn("--all-threads", error_msg)
         self.assertIn("incompatible with --async-aware", error_msg)
 
+    def test_async_aware_incompatible_with_binary(self):
+        """Test --async-aware is incompatible with --binary."""
+        test_args = ["profiling.sampling.cli", "attach", "12345",
+                     "--async-aware", "--binary"]
+
+        with (
+            mock.patch("sys.argv", test_args),
+            mock.patch("sys.stderr", io.StringIO()) as mock_stderr,
+            self.assertRaises(SystemExit) as cm,
+        ):
+            main()
+
+        self.assertEqual(cm.exception.code, 2)  # argparse error
+        error_msg = mock_stderr.getvalue()
+        self.assertIn("--binary", error_msg)
+        self.assertIn("incompatible with --async-aware", error_msg)
+
     @unittest.skipIf(is_emscripten, "subprocess not available")
     def test_run_nonexistent_script_exits_cleanly(self):
         """Test that running a non-existent script exits with a clean error."""