Skip to content

Commit

Permalink
add signal handler SIGIN/SIGTERM to ros2run.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Aug 3, 2024
1 parent ecfd2ed commit 6177388
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ros2run/ros2run/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ def run_executable(*, path, argv, prefix=None):
cmd = prefix + cmd

process = subprocess.Popen(cmd)

# add signal handler for the parent process, so that we can finalize the child process
def signal_handler(sig, frame):
print(ROS2RUN_MSG_PREFIX, 'Received signal: ', signal.strsignal(sig))
if process.poll() is None:
# If child process is running, forward the signal to it
process.send_signal(sig)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)

while process.returncode is None:
try:
process.communicate()
Expand Down

0 comments on commit 6177388

Please sign in to comment.