22 lines
463 B
Python
22 lines
463 B
Python
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]
|
|
|
|
|
|
|