added Executor that knows its futures
This commit is contained in:
@@ -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]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user