So I use the .run_in_executor()
method of the event loop to create a new process to perform my method:
executor = ProcessPoolExecutor(5)
list_of_futures = []
def run_in_another_process(func: Callable, *args, **kwargs) -> asyncio.Future:
loop = asyncio.get_event_loop()
future = loop.run_in_executor(executor=executor, func=functools.partial(func, *args, **kwargs))
list_of_futures.append(future)
return future
And it works fine. But when I try to cancel a future using cancel()
method, it just does nothing, even though it's marked as canceled:
list_of_futures[0].cancel()
# True, but it's still in the RAM and is being performed!
list_of_futures[0].cancelled()
So the question is, how to cancel asyncio.Future
properly? Why default method doesn't work?