You can see the full here.
A simplified version of my code follows:
executor = ProcessPoolExecutor(10)
try:
coro = bot.loop.run_in_executor(executor, processUserInput, userInput)
result = await asyncio.wait_for(coro, timeout=10.0, loop=bot.loop)
except asyncio.TimeoutError:
result="Operation took longer than 10 seconds. Aborted."
Unfortunately, when an operation times out, that process is still running, even though the future has been cancelled. How do I cancel that process/task so that it actually stops running?
ProcessPoolExecutor
uses themultiprocessing
module. Instead of canceling the event, which does not.terminate()
the subprocess, It is recommended to use amultiprocessing.Event
to allow your subprocess to exit properly: