Fix hang on shutdown when asyncio.create_subprocess is used - #44
Merged
Merged
Conversation
cdleonard
force-pushed
the
feature/fix-async-hang
branch
from
March 31, 2026 13:06
3e607f4 to
6a5960d
Compare
Owner
The rest of the code uses result instead of retval
Replace timeout=2 in multiple places with a constant and raise the value.
cdleonard
force-pushed
the
feature/fix-async-hang
branch
from
April 1, 2026 10:13
6a5960d to
55425c5
Compare
Contributor
Author
|
Removed dependency on #42 |
Owner
|
@cdleonard awesome, thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #41 - can now using asyncio.create_subprocess while coverage_sh is enabled.
As far as I can tell asyncio.create_subprocess will initialize a
subprocess.Popenobject internally and use it with a custom PID waiter, skippingPopen.waitandPopen.poll. I was only able to get this to work by hooking intoPopen.__del__.There are other use cases where hooking
Popen.__del__is useful, for example if the user simply leaks asubprocess.Popenthat shouldn't cause coverage_sh threads to simple hang.It might make sense to also mark
CoverageParserThreadas a daemon thread. This shouldn't replace the__del__hook because then threads would leak until main process exit.Includes a new
test_end2end_async_simplewhich does coverage on a newmain_async.pyscript which callsasyncio.create_subprocess. WithoutPatchedPopen.__del__it hangs - demonstrating the original issue. It also surprisingly shows that coverage works as expected!