Hi, I thought maybe a callback before the worker of a Executor finishes would be helpful. It would allow the setup and teardown resources (such as file, databases, connections, ...) across workers. My particular use case is for closing down requests.Session objects, that currently its very complicated to cleanup properly. There are many other use cases, a generic format would be something like the following:
from concurrent.futures import ThreadPoolExecutor
worker_local = threading.local()
# Initialize costly resources for a particular worker
worker_local.resources = ...
# Deinitialize worker resources carefully
with ThreadPoolExecutor(initializer=session_initializer, deinitializer=session_deinitializer) as executor: