From 26fb788144ca9248aebbc61fcb9001790e9168d0 Mon Sep 17 00:00:00 2001 From: Darko Lukic Date: Mon, 21 Jun 2021 12:08:58 +0200 Subject: [PATCH 1/4] Respawn a process only if `returncode != 0` Signed-off-by: Darko Lukic --- launch/launch/actions/execute_process.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch/launch/actions/execute_process.py b/launch/launch/actions/execute_process.py index dbdb90886..ba1b9b4ad 100644 --- a/launch/launch/actions/execute_process.py +++ b/launch/launch/actions/execute_process.py @@ -766,7 +766,7 @@ async def __execute_process(self, context: LaunchContext) -> None: )) await context.emit_event(ProcessExited(returncode=returncode, **process_event_args)) # respawn the process if necessary - if not context.is_shutdown and not self.__shutdown_future.done() and self.__respawn: + if not context.is_shutdown and not self.__shutdown_future.done() and self.__respawn and returncode != 0: if self.__respawn_delay is not None and self.__respawn_delay > 0.0: # wait for a timeout(`self.__respawn_delay`) to respawn the process # and handle shutdown event with future(`self.__shutdown_future`) From ec022d269efbf493c4be939d4de0443da804ab17 Mon Sep 17 00:00:00 2001 From: Darko Lukic Date: Mon, 21 Jun 2021 12:23:30 +0200 Subject: [PATCH 2/4] Line length Signed-off-by: Darko Lukic --- launch/launch/actions/execute_process.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/launch/launch/actions/execute_process.py b/launch/launch/actions/execute_process.py index ba1b9b4ad..eaa4372a1 100644 --- a/launch/launch/actions/execute_process.py +++ b/launch/launch/actions/execute_process.py @@ -766,7 +766,8 @@ async def __execute_process(self, context: LaunchContext) -> None: )) await context.emit_event(ProcessExited(returncode=returncode, **process_event_args)) # respawn the process if necessary - if not context.is_shutdown and not self.__shutdown_future.done() and self.__respawn and returncode != 0: + if not context.is_shutdown and not self.__shutdown_future.done() and self.__respawn and \ + returncode != 0: if self.__respawn_delay is not None and self.__respawn_delay > 0.0: # wait for a timeout(`self.__respawn_delay`) to respawn the process # and handle shutdown event with future(`self.__shutdown_future`) From 8d38cbfaacf6fd33545e702f26235759ab810749 Mon Sep 17 00:00:00 2001 From: Darko Lukic Date: Mon, 21 Jun 2021 12:32:54 +0200 Subject: [PATCH 3/4] Test Signed-off-by: Darko Lukic --- launch/test/launch/test_execute_process.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch/test/launch/test_execute_process.py b/launch/test/launch/test_execute_process.py index bfbcd069d..d44721821 100644 --- a/launch/test/launch/test_execute_process.py +++ b/launch/test/launch/test_execute_process.py @@ -152,7 +152,7 @@ def generate_launch_description(): return LaunchDescription([ ExecuteProcess( - cmd=[sys.executable, '-c', "print('action')"], + cmd=[sys.executable, '-c', "print('action'); false"], respawn=True, respawn_delay=respawn_delay, on_exit=on_exit_callback ), From 108ad50a4a77088cbd48645877e4cde2c66ed5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darko=20Luki=C4=87?= Date: Sat, 3 Jul 2021 16:19:40 +0200 Subject: [PATCH 4/4] Update test_execute_process.py Signed-off-by: Darko Lukic --- launch/test/launch/test_execute_process.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch/test/launch/test_execute_process.py b/launch/test/launch/test_execute_process.py index d44721821..9a422dbdb 100644 --- a/launch/test/launch/test_execute_process.py +++ b/launch/test/launch/test_execute_process.py @@ -152,7 +152,7 @@ def generate_launch_description(): return LaunchDescription([ ExecuteProcess( - cmd=[sys.executable, '-c', "print('action'); false"], + cmd=[sys.executable, '-c', "import sys; print('action'); sys.exit(1)"], respawn=True, respawn_delay=respawn_delay, on_exit=on_exit_callback ),