-
Notifications
You must be signed in to change notification settings - Fork 158
Kill dangling subprocesses #632
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
base: rolling
Are you sure you want to change the base?
Changes from all commits
f86971a
d268600
b5a925f
e2b1a3c
8466b49
2356223
ac6afd3
7ffee9a
6432d76
6284c82
514c149
5b43cdc
4b796cc
58cd661
5ff2f05
b5ba458
fc97730
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,11 @@ | |
|
||
"""Tests for the ExecuteLocal Action.""" | ||
|
||
import asyncio | ||
import os | ||
import signal | ||
import sys | ||
import time | ||
|
||
from launch import LaunchDescription | ||
from launch import LaunchService | ||
|
@@ -28,6 +31,8 @@ | |
from launch.actions import TimerAction | ||
from launch.descriptions import Executable | ||
|
||
import psutil | ||
|
||
import pytest | ||
|
||
|
||
|
@@ -138,3 +143,39 @@ def test_execute_process_with_output_dictionary(): | |
ls = LaunchService() | ||
ls.include_launch_description(ld) | ||
assert 0 == ls.run() | ||
|
||
|
||
PYTHON_SCRIPT = """\ | ||
import time | ||
|
||
while 1: | ||
time.sleep(0.5) | ||
""" | ||
|
||
|
||
def test_kill_subprocesses(): | ||
"""Test launching a process with an environment variable.""" | ||
executable = ExecuteLocal( | ||
process_description=Executable( | ||
cmd=['python3', '-c', f'"{PYTHON_SCRIPT}"'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this sufficient to test the feature? Is it the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This shows that the feature works. |
||
), | ||
shell=True, | ||
output='screen', | ||
) | ||
ld = LaunchDescription([executable]) | ||
ls = LaunchService() | ||
ls.include_launch_description(ld) | ||
loop = asyncio.new_event_loop() | ||
asyncio.set_event_loop(loop) | ||
run_async_task = loop.create_task(ls.run_async()) | ||
|
||
async def wait_for_subprocesses(): | ||
start = time.time() | ||
while len(psutil.Process().children(recursive=True)) != 2: | ||
await asyncio.sleep(0.5) | ||
assert time.time() < start + 5., 'timed out waiting for processes to setup' | ||
wait_for_subprocesses_task = loop.create_task(wait_for_subprocesses()) | ||
loop.run_until_complete(wait_for_subprocesses_task) | ||
os.kill(executable.process_details['pid'], signal.SIGTERM) | ||
loop.run_until_complete(run_async_task) | ||
assert len(psutil.Process().children(recursive=True)) == 0 |
Uh oh!
There was an error while loading. Please reload this page.