From 20b52c1ee36f892daa1467c2cec18d894e024560 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 27 Feb 2019 02:31:50 +0000 Subject: process: Speed-up terminating lots of processes by batching it Introduce a strategy to terminate processes and begin with an implementation for parallel (that has no degree of parallelism right now). Change-Id: I7dd4a7e26aca758198aa08a434eaf5f3f5af632d --- src/osmo_gsm_tester/process.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/osmo_gsm_tester/process.py') diff --git a/src/osmo_gsm_tester/process.py b/src/osmo_gsm_tester/process.py index b1769f8..1e53aba 100644 --- a/src/osmo_gsm_tester/process.py +++ b/src/osmo_gsm_tester/process.py @@ -21,12 +21,38 @@ import os import time import subprocess import signal +from abc import ABCMeta, abstractmethod from datetime import datetime from . import log from .event_loop import MainLoop from .util import Dir +class TerminationStrategy(log.Origin, metaclass=ABCMeta): + """A baseclass for terminating a collection of processes.""" + + def __init__(self): + self._processes = [] + + def add_process(self, process): + """Remembers a process that needs to be terminated.""" + self._processes.append(process) + + @abstractmethod + def terminate_all(self): + "Terminates all scheduled processes and waits for the termination.""" + pass + + +class ParallelTerminationStrategy(TerminationStrategy): + """Processes will be terminated in parallel.""" + + def terminate_all(self): + # TODO(zecke): Actually make this non-sequential. + for process in self._processes: + process.terminate() + + class Process(log.Origin): def __init__(self, name, run_dir, popen_args, **popen_kwargs): -- cgit v1.2.3