[New-bugs-announce] [issue38988] Killing asyncio subprocesses on timeout?
report at bugs.python.org
Fri Dec 6 12:41:00 EST 2019
New submission from dontbugme <pythonbugsbugmenot at spamavert.com>:
I'm trying to use asyncio.subproceess and am having difficulty killing the subprocesses after timeout. My use case is launching processes that hold on to file handles and other exclusive resources, so subsequent processes can only be launched after the first ones are fully stopped.
The documentation on https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process say there is no timeout-parameter and suggests using wait_for() instead.
I tried this but it's kind of a footgun because the wait_for() times out but the process still lives on in the background. See Fail(1) and Fail(2) in attached test1().
To solve this i tried to catch the CancelledError and in the exception handler kill the process myself. While this worked it's also semi dangerous because it takes some time for the process to get killed and the wait() after kill() runs in the background as some kind of detached task. See Fail(3) in attached test2().
This i can sortof understand because after TimeoutError something would have to block for wait() to actually finish and this is impossible.
After writing this i feel myself there is no good solution for Fail#3 because again, timeouts can't be blocking. Maybe some warning in the documentation would be appropriate for Fail(1+2) because the suggestion in the documentation right now is quite misleading, the wait_for()-alternative to timeout-parameter does not behave like the timeout-parameter in ordinary subprocess.Popen.wait()
nosy: asvetlov, dontbugme, yselivanov
title: Killing asyncio subprocesses on timeout?
versions: Python 3.6
Added file: https://bugs.python.org/file48761/subprocess_timeout.py
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce