Skip to content

Commit

Permalink
stop scenarios in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
willcl-ark committed Dec 5, 2024
1 parent 2526957 commit 5c18af9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/warnet/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import zipapp
from concurrent.futures import ThreadPoolExecutor, as_completed
from multiprocessing import Pool
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -112,10 +113,18 @@ def stop_scenario(scenario_name):


def stop_all_scenarios(scenarios):
"""Stop all active scenarios using Helm"""
with console.status("[bold yellow]Stopping all scenarios...[/bold yellow]"):
for scenario in scenarios:
stop_scenario(scenario)
"""Stop all active scenarios in parallel using multiprocessing"""

def stop_single(scenario):
stop_scenario(scenario)
return f"Stopped scenario: {scenario}"

with console.status("[bold yellow]Stopping all scenarios...[/bold yellow]"), Pool() as pool:
results = pool.map(stop_single, scenarios)

for result in results:
console.print(f"[bold green]{result}[/bold green]")

console.print("[bold green]All scenarios have been stopped.[/bold green]")


Expand Down

0 comments on commit 5c18af9

Please sign in to comment.