Skip to content

Improve the process cleanup logic when running tests #616

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

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 7 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import gc
from contextlib import suppress

import psutil
import pytest
Expand Down Expand Up @@ -40,13 +39,12 @@ def cleanup_children():

children = psutil.Process().children(recursive=True)
if children:
logger.info(f"Cleaning up {len(children)} leftover child processes")
for child in children:
with suppress(psutil.NoSuchProcess):
child.terminate()
psutil.wait_procs(children, timeout=1)
for child in children:
with suppress(psutil.NoSuchProcess):
child.kill()
gone, alive = psutil.wait_procs(children, timeout=0.1)
logger.debug(f"Cleaning up {len(alive)} leftover child processes")
for child in alive:
child.terminate()
gone, alive = psutil.wait_procs(alive, timeout=1)
for child in alive:
child.kill()

MPFuture.reset_backend()
1 change: 1 addition & 0 deletions tests/test_allreduce_fault_tolerance.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,4 @@ def _make_tensors():

for averager in averagers:
averager.shutdown()
dht.shutdown()
6 changes: 6 additions & 0 deletions tests/test_dht_experts.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def test_beam_search(
assert all(isinstance(e, hivemind.RemoteExpert) for experts in batch_experts for e in experts)
assert all(len(experts) == beam_size for experts in batch_experts)

you.shutdown()
for dht_instance in dht_instances:
dht_instance.shutdown()


@pytest.mark.forked
def test_dht_single_node():
Expand Down Expand Up @@ -119,6 +123,8 @@ def test_dht_single_node():
with pytest.raises(AssertionError):
beam_search.get_active_successors(["e.1.2.", "e.2", "e.4.5."])

node.shutdown()


def test_uid_patterns():
valid_experts = [
Expand Down
Loading