diff --git a/modman/executing.py b/modman/executing.py new file mode 100644 index 0000000..768b417 --- /dev/null +++ b/modman/executing.py @@ -0,0 +1,21 @@ +from concurrent.futures import ThreadPoolExecutor + + +class Executor(ThreadPoolExecutor): + + def __init__(self): + super().__init__() + self.futures = {} + + def run(self, name, func, *args, **kwargs): + fut = self.submit(func, *args, **kwargs) + self.futures[name] = fut + return fut + + def cleanup(self): + for name, fut in tuple(self.futures.items()): + if fut.done(): + del self.futures[name] + + +