Skip to content

gh-110147: run console io test in new process #110268

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
merged 13 commits into from
Oct 5, 2023

Conversation

aisk
Copy link
Contributor

@aisk aisk commented Oct 3, 2023

@aisk aisk requested a review from a team as a code owner October 3, 2023 12:47
@aisk
Copy link
Contributor Author

aisk commented Oct 3, 2023

Latest 4 tests passed https://github.com/python/cpython/actions/workflows/build.yml?query=branch%3A%27test-msvcrt-process%27

Except https://github.com/python/cpython/actions/runs/6392768647 failed with test.test_multiprocessing_spawn.test_manager, but I think it do not caused by this change.

@aisk aisk requested a review from vstinner October 3, 2023 13:53
import msvcrt
assert msvcrt.kbhit() == 0
''')
self.run_in_separated_process(code)

def test_getch(self):
msvcrt.ungetch(b'c')
self.assertEqual(msvcrt.getch(), b'c')

def test_getwch(self):
Copy link
Member

Choose a reason for hiding this comment

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

test_getwche() looks like a copy/paste, you just replaced getwch() with getwche(). Can you rename the function to check_getwch(func), so test_getwch() would call check_getwch("getwch") and test_getwch() would call check_getwch("getwche")?

write_input(stdin, {repr(c_encoded)})
assert msvcrt.getwch() == "{c}"
''')
self.run_in_separated_process(code)

def test_getche(self):
msvcrt.ungetch(b'c')
self.assertEqual(msvcrt.getche(), b'c')
Copy link
Member

Choose a reason for hiding this comment

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

It may be safer to run this test in a subprocess with a new console, no?

Copy link
Member

Choose a reason for hiding this comment

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

Yes it would, but it's annoying. We might want to put it behind a resource marker, as the new console will pop up new GUI when it runs.

Copy link
Member

Choose a reason for hiding this comment

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

Would CREATE_NO_WINDOW flag prevent popups?

The process is a console application that is being run without a console window. Therefore, the console handle for the application is not set. This flag is ignored if the application is not a console application, or if it is used with either CREATE_NEW_CONSOLE or DETACHED_PROCESS.

says: https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems it should work, I'll try it.

Copy link
Member

Choose a reason for hiding this comment

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

the console handle for the application is not set

Means no console and the test is irrelevant.

ignored if ... used with either CREATE_NEW_CONSOLE

This is the flag that you'd use to make the test more reliable, and it's incompatible with CREATE_NO_WINDOW.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, and added the @requires_resource('gui') marker to avoid the console pop-up.

For the tests test_getche and test_getch, they uses msvcrt.ungetch instead of the magic write_input, I think this stuff is stable enough, this test file is added and disabled days ago, so I fixed it serveral times, and never saw them failed once. So I think we should keep it (test_getche / test_getch) as current.

Copy link
Member

Choose a reason for hiding this comment

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

For the tests test_getche and test_getch, they uses msvcrt.ungetch instead of the magic write_input, I think this stuff is stable enough

Hum, ok. Let's see if CI will agree with you :-) I'm fine with keeping them in the same process for now.

@vstinner
Copy link
Member

vstinner commented Oct 3, 2023

@aisk: Please, don't touch anything, I will schedule buildbot jobs to test your PR :-)

@vstinner
Copy link
Member

vstinner commented Oct 3, 2023

!buildbot Windows

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @vstinner for commit a3d0008 🤖

The command will test the builders whose names match following regular expression: Windows

The builders matched are:

  • AMD64 Windows11 Non-Debug PR
  • AMD64 Windows10 PR
  • ARM64 Windows PR
  • ARM64 Windows Non-Debug PR
  • AMD64 Windows11 Refleaks PR
  • AMD64 Windows11 Bigmem PR

@vstinner
Copy link
Member

vstinner commented Oct 5, 2023

test_msvcrt passed on the two GHA Windows jobs and on the 6 buildbots. So it looks good to me.

buildbot/AMD64 Windows11 Refleaks PR — Build done.

test__xxinterpchannels leaked [21, 21, 21] references, sum=63
test_interpreters leaked [12, 12, 12] references, sum=36

These errors are unrelated and can be ignored.

@vstinner vstinner merged commit 1f3af03 into python:main Oct 5, 2023
@vstinner
Copy link
Member

vstinner commented Oct 5, 2023

Merged, thanks @aisk for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants