Author dontbugme
Recipients asvetlov, dontbugme, yselivanov
Date 2019-12-06.17:41:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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 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()
Date User Action Args
2019-12-06 17:41:00dontbugmesetrecipients: + dontbugme, asvetlov, yselivanov
2019-12-06 17:41:00dontbugmesetmessageid: <>
2019-12-06 17:41:00dontbugmelinkissue38988 messages
2019-12-06 17:41:00dontbugmecreate