@@ -822,6 +822,7 @@ def test_cancel_notify(
822822 # Test that NOTIFY_THEN_CANCEL first signals a SIGTERM and then a SIGKILL
823823
824824 # GIVEN
825+ proc_id : Optional [int ] = None
825826 logger = build_logger (queue_handler )
826827 with NotifyingRunner (logger = logger , session_working_directory = tmp_path ) as runner :
827828 python_app_loc = (
@@ -833,6 +834,7 @@ def test_cancel_notify(
833834 secs = 2 if not is_windows () else 5
834835 time .sleep (secs ) # Give the process a little time to do something
835836 now = datetime .now (timezone .utc )
837+ proc_id = runner ._process ._pid
836838 runner .cancel (time_limit = timedelta (seconds = 2 ))
837839
838840 # THEN
@@ -849,9 +851,10 @@ def test_cancel_notify(
849851 messages = collect_queue_messages (message_queue )
850852 assert "Trapped" in messages
851853 trapped_idx = messages .index ("Trapped" )
854+ process_exit_idx = messages .index (f"Process pid { proc_id } exited with code: { runner .exit_code } (unsigned) / { hex (runner .exit_code )} (hex)" )
852855 # Should be at least one more number printed after the Trapped
853856 # to indicate that we didn't immediately terminate the script.
854- assert messages [trapped_idx + 1 ]. isdigit ( )
857+ assert any ( msg . isdigit () for msg in messages [trapped_idx + 1 : process_exit_idx ] )
855858 # Didn't get to the end
856859 assert "Log from test 9" not in messages
857860 # Notification file exists
0 commit comments