Skip to content

Commit

Permalink
Applies misc fixes after Windows triaging.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Feb 18, 2019
1 parent aec02bf commit d26d890
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
28 changes: 11 additions & 17 deletions launch/launch/actions/execute_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@
_global_process_counter = 0 # in Python3, this number is unbounded (no rollover)


def _is_process_running(pid):
try:
os.kill(pid, 0)
return True
except OSError:
return False


class ExecuteProcess(Action):
"""Action that begins executing a process and sets up event handlers for the process."""

Expand Down Expand Up @@ -254,12 +246,9 @@ def __on_signal_process_event(
raise RuntimeError('Signal event received before execution.')
if self._subprocess_transport is None:
raise RuntimeError('Signal event received before subprocess transport available.')
# if self._subprocess_protocol.complete.done():
# disable above's check as this handler may get called *after* the process has
# terminated but *before* the asyncio future has been resolved.
if not _is_process_running(self._subprocess_transport.get_pid()):
if self._subprocess_protocol.complete.done():
# the process is done or is cleaning up, no need to signal
_logger.debug("signal '{}' not set to '{}' because it is already closing".format(
_logger.debug("signal '{}' not sent to '{}' because it is already closing".format(
typed_event.signal_name, self.process_details['name']
))
return None
Expand All @@ -274,11 +263,16 @@ def __on_signal_process_event(
_logger.info("sending signal '{}' to process[{}]".format(
typed_event.signal_name, self.process_details['name']
))
if typed_event.signal_name == 'SIGKILL':
self._subprocess_transport.kill() # works on both Windows and POSIX
try:
if typed_event.signal_name == 'SIGKILL':
self._subprocess_transport.kill() # works on both Windows and POSIX
return None
self._subprocess_transport.send_signal(typed_event.signal)
return None
self._subprocess_transport.send_signal(typed_event.signal)
return None
except ProcessLookupError:
_logger.debug("signal '{}' not sent to '{}' because it has closed already".format(
typed_event.signal_name, self.process_details['name']
))

def __on_process_stdin_event(
self,
Expand Down
2 changes: 1 addition & 1 deletion launch_testing/launch_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def add_test_action(
def on_test_process_exit(event, context):
if event.returncode != 0:
process_name = event.action.process_details['name']
self._processes_rc[process_name] = event.returncode
self.__processes_rc[process_name] = event.returncode
return self._fail(
test_name, reason='{} test failed!'.format(
process_name
Expand Down

0 comments on commit d26d890

Please sign in to comment.