From 894e97d1ca6500ca43df47b38e9c254961f7d8ac Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sat, 6 Feb 2021 19:02:55 +0000 Subject: [PATCH] instead of waiting for all futures to end in each iteration, go to next iteration and don't start another of a still running one --- modman/main.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/modman/main.py b/modman/main.py index 772fe93..236e51c 100755 --- a/modman/main.py +++ b/modman/main.py @@ -10,14 +10,29 @@ folder = "scripts" mm = ModuleManager(folder) mods = mm.modules -while True: - mm.update() - with ThreadPoolExecutor() as ex: - for f in mods.values(): + +futs = {} + +with ThreadPoolExecutor() as ex: + while True: + mm.update() + + for n, fut in tuple(futs.items()): + if fut.done(): + del futs[n] + + print("not done:", futs) + + for n, f in mods.items(): + if n in futs: + print(f"{n} still running... will not start again") + continue + fut = ex.submit(f) print(fut) + futs[n] = fut - sleep(1) + sleep(1)