From 8aebb82882f5e1873462a40d281a2013ff7fed96 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sat, 6 Feb 2021 20:18:32 +0000 Subject: [PATCH] added Executor that knows its futures --- modman/executing.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 modman/executing.py 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] + + +