Skip to content

Commit 6d8b963

Browse files
authored
Fix for failure in the benchmark_launch when using Process.wait twice (#2076)
- Address failure: "child process pid 116528 exit status already read: will report returncode 255" by avoiding usage Process.wait twice. - Note: the second time Process.wait calling from the def test_proc_terminates(self, last_benchmark): # Wait for the last benchmark to complete before processing the results self.proc_info.assertWaitForShutdown(process=last_benchmark,timeout=600) - Explanation and RCA: In Python 3.12, the internal implementation of process management and resource cleanup (especially around wait() and exit status handling) has become stricter and more robust. Double-waiting on a process (calling wait() twice) can now trigger errors or warnings, such as "exit status already read," because the exit status is only meant to be consumed once. In Python 3.8, this was more permissive or silent, but in newer versions, the subprocess module may raise exceptions or log messages if you try to wait for a process whose exit status has already been collected. Signed-off-by: Michael Orlov <[email protected]>
1 parent e8cbb1f commit 6d8b963

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

rosbag2_performance/rosbag2_performance_benchmarking/launch/benchmark_launch.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import shutil
5252
import signal
5353
import sys
54+
import time
5455

5556
from ament_index_python import get_package_share_directory
5657
import launch
@@ -267,9 +268,19 @@ def _producer_node_exited(event, context):
267268
]
268269
_recorder_cpu_usage = _rosbag_process.cpu_percent()
269270
os.kill(_rosbag_pid, signal.SIGINT)
270-
# Wait for rosbag2 process to exit for 10 seconds
271-
rosbag_return_code = _rosbag_process.wait(10)
272271
_rosbag_pid = None
272+
# Wait for rosbag2 process to exit for 10 seconds
273+
timeout = 10
274+
start_time = time.time()
275+
rosbag_return_code = None
276+
# Note: we cant use _rosbag_process.wait(10) because wait shall be called only once.
277+
# We will have to call wait one more time in the test_proc_terminates(self, last_benchmark)
278+
while time.time() - start_time < timeout:
279+
if not _rosbag_process.is_running():
280+
rosbag_return_code = _rosbag_process.returncode()
281+
break
282+
time.sleep(0.1)
283+
273284
if rosbag_return_code is not None and rosbag_return_code != 0:
274285
return [
275286
launch.actions.LogInfo(msg='Rosbag2 record error. Shutting down benchmark. '

0 commit comments

Comments
 (0)