Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx> --- client/tests/kvm/kvm_utils.py | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 5d79112..57c9951 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -1046,7 +1046,7 @@ def get_vendor_from_pci_id(pci_id): class Thread(threading.Thread): """ - Runs a test in the background thread. + Run a function in a background thread. """ def __init__(self, target, args=(), kwargs={}): """ @@ -1102,6 +1102,28 @@ class Thread(threading.Thread): self._retval = None +def parallel(targets): + """ + Run multiple functions in parallel. + + @param targets: A sequence of tuples or functions. If it's a sequence of + tuples, each tuple will be interpreted as (target, args, kwargs) or + (target, args) or (target,) depending on its length. If it's a + sequence of functions, the functions will be called without + arguments. + @return: A list of the values returned by the functions called. + """ + threads = [] + for target in targets: + if isinstance(target, tuple) or isinstance(target, list): + t = Thread(*target) + else: + t = Thread(target) + threads.append(t) + t.start() + return [t.join() for t in threads] + + class KvmLoggingConfig(logging_config.LoggingConfig): """ Used with the sole purpose of providing convenient logging setup -- 1.7.3.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html