If you send a function to ThreadPoolExecutor , the executor will run the function in the stream and store its return value in the Future object. Since the number of concurrent threads is limited, you have the option to cancel the pending execution of the future, but once control in the workflow thread has been transferred to the callee, there is no way to stop execution.
Consider this code:
import concurrent.futures as f import time T = f.ThreadPoolExecutor(1)
In general, whenever you want to cancel something, you are responsible for making sure that this is so.
However, there are some ready-made options. For example, consider using asyncio , they also have an example of using sleep . The concept bypasses the problem when any potential locking operation should be called, instead returning control to the control loop that works in the majority of the context, along with a note that execution should continue whenever the result is available, or, in your case, after n seconds.
source share