summaryrefslogtreecommitdiffstats
path: root/src/osmo_gsm_tester/process.py
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2019-02-27 02:31:50 +0000
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2019-03-04 06:53:51 +0000
commit20b52c1ee36f892daa1467c2cec18d894e024560 (patch)
treef17909c2488ec15b4085ebb81c57f1f5142d87bc /src/osmo_gsm_tester/process.py
parentf922a998cb3636b0b62b99fcef9212000103e19c (diff)
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
Diffstat (limited to 'src/osmo_gsm_tester/process.py')
-rw-r--r--src/osmo_gsm_tester/process.py26
1 files changed, 26 insertions, 0 deletions
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):