Skip to content

Commit 6177388

Browse files
committed
add signal handler SIGIN/SIGTERM to ros2run.
Signed-off-by: Tomoya Fujita <[email protected]>
1 parent ecfd2ed commit 6177388

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ros2run/ros2run/api/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ def run_executable(*, path, argv, prefix=None):
6262
cmd = prefix + cmd
6363

6464
process = subprocess.Popen(cmd)
65+
66+
# add signal handler for the parent process, so that we can finalize the child process
67+
def signal_handler(sig, frame):
68+
print(ROS2RUN_MSG_PREFIX, 'Received signal: ', signal.strsignal(sig))
69+
if process.poll() is None:
70+
# If child process is running, forward the signal to it
71+
process.send_signal(sig)
72+
signal.signal(signal.SIGINT, signal_handler)
73+
signal.signal(signal.SIGTERM, signal_handler)
74+
6575
while process.returncode is None:
6676
try:
6777
process.communicate()

0 commit comments

Comments
 (0)