I would like to subclass the Future class of the
The Future class encapsulates the asynchronous execution of a callable. Future instances are created by Executor.submit().
for my_future in concurrent.futures.as_completed(...):
So, here comes the trick. You can subclass and replace the original Future, and then add custom methods in the subclass.
It's doable, but not recommended. It's better to use composition rather than inheritance for this purpose. There is a good chapter on inheritance and composition in Learn Python the Hard Way
Back to the the question, here is a composition example:
class Myclass(object): def __init__(self, workers=3): self.executor = concurrent.futures.ProcessPoolExcutor(workers) def run(self, job): '''Job to be run in a Executor''' def submit(self, jobs): self.futures = [executor.submit(self, foo, job) for job in jobs] def done(self, result): '''Dealing with the result''' def harvest(self): for my_future in concurrent.futures.as_completed(self.futures): self.done(my_future.result())
And then you can subclass
MyClass and implement different done method.