Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add signal handler SIGIN/SIGTERM to ros2run. #899

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
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)
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved

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