Python: concurrent.futures: cannot be undone

This small snippet prints False

 import subprocess from concurrent import futures with futures.ThreadPoolExecutor(max_workers=1) as executor: future=executor.submit(subprocess.call, ['sleep', '2']) print(future.cancel()) 

According to the docs, this means โ€œthe future cannot be undoneโ€: https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.Future.cancel

cancel () : attempt to cancel the call. If the call is currently being made and cannot be canceled, the method will return False, otherwise the call will be canceled and the method will return True.

Is there a way to undo the future, although the cancel() methods tell me that it cannot be undone?

I am running backport on Python 2.7

+6
source share

All Articles