Skip to content

bpo-30121: Fix debug assert in subprocess on Windows #1224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

segevfiner
Copy link
Contributor

@segevfiner segevfiner commented Apr 20, 2017

This is caused by closing HANDLEs using os.close which is for CRT file
descriptors and not for HANDLEs.

http://bugs.python.org/issue30121

@mention-bot
Copy link

@segevfiner, thanks for your PR! By analyzing the history of the files in this pull request, we identified @gpshead, @tim-one and @rosslagerwall to be potential reviewers.

@segevfiner
Copy link
Contributor Author

ping @Haypo since you marked yourself for review some time ago but might have forgotten about this 😉

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to write an unit test? Try to mock the _execute_child() method to raise an exception for example?

This is caused by closing HANDLEs using os.close which is for CRT file
descriptors and not for HANDLEs.
@segevfiner
Copy link
Contributor Author

@Haypo Plenty of tests already trigger this. And any simple test that just tries to run a non-existent executable with io redirection will also trigger this. But libregrtest does CrtSetReportMode which means the assert will be silent when ran using it, and the test will simply pass. If you try and run python -m unittest -v test.test_subprocess in a debug build, you can see the asserts.

I did encounter one test in test_subprocess that will assert when ran directly so I suppressed that, and you should be able to run test_subprocess and see that it doesn't assert in this branch.

I don't know how to write a test that checks specifically that there isn't a debug assertion under libregrtest.

@segevfiner segevfiner force-pushed the issue-30121-windows-subprocess-debug-assert branch from 72ed71a to 6dd5a06 Compare June 6, 2017 17:26
@vstinner
Copy link
Member

Sorry, it took me a while to understand the fixed bug, but now I understood the 3 changes and they all LGTM. I had to play with subprocess to understand why we need all these changes.

@vstinner vstinner merged commit 4d38517 into python:master Aug 18, 2017
@vstinner
Copy link
Member

I wrote an unit test for this change: PR #3133.

vstinner added a commit that referenced this pull request Aug 21, 2017
…3173)

* bpo-30121: Fix debug assert in subprocess on Windows (#1224)

* bpo-30121: Fix debug assert in subprocess on Windows

This is caused by closing HANDLEs using os.close which is for CRT file
descriptors and not for HANDLEs.

* bpo-30121: Suppress debug assertion in test_subprocess when ran directly

(cherry picked from commit 4d38517)

* Add test_subprocess.test_nonexisting_with_pipes() (#3133)

bpo-30121: Test the Popen failure when Popen was created with pipes.
Create also NONEXISTING_CMD variable in test_subprocess.py.
(cherry picked from commit 9a83f65)
@segevfiner segevfiner deleted the issue-30121-windows-subprocess-debug-assert branch August 22, 2017 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants