From 61bb57fa3fb59e545561df65b655ac137063a30e Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sat, 27 Jun 2026 19:24:53 +0200 Subject: [PATCH] [3.15] gh-152434: Block --async-aware with --binary (GH-152444) (#152446) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Lib/profiling/sampling/cli.py | 4 +++- .../test_sampling_profiler/test_cli.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Lib/profiling/sampling/cli.py b/Lib/profiling/sampling/cli.py index a5d9573ae6b..0330c15c014 100644 --- a/Lib/profiling/sampling/cli.py +++ b/Lib/profiling/sampling/cli.py @@ -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: diff --git a/Lib/test/test_profiling/test_sampling_profiler/test_cli.py b/Lib/test/test_profiling/test_sampling_profiler/test_cli.py index 9c0734ac804..0181095ca21 100644 --- a/Lib/test/test_profiling/test_sampling_profiler/test_cli.py +++ b/Lib/test/test_profiling/test_sampling_profiler/test_cli.py @@ -866,6 +866,23 @@ def test_async_aware_incompatible_with_all_threads(self): 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."""