Skip to content

speedup test_pyrepl #132688

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 1 commit into from
Apr 19, 2025
Merged

speedup test_pyrepl #132688

merged 1 commit into from
Apr 19, 2025

Conversation

chris-eibl
Copy link
Member

@chris-eibl chris-eibl commented Apr 18, 2025

Speedup test_pyrepl by speeding up test_unix_console.py / test_windows_console.py. Especially in case of Windows, almost all the time is spent there, and these tests are unnecessarily slow because they are not mocking wait:

def wait(self, timeout: float | None = None) -> bool:
"""
Wait for events on the console.
"""
return (
not self.event_queue.empty()
or self.more_in_buffer()
or bool(self.pollob.poll(timeout))
)

def wait(self, timeout: float | None) -> bool:
"""Wait for an event."""
# Poor man's Windows select loop
start_time = time.time()
while True:
if msvcrt.kbhit(): # type: ignore[attr-defined]
return True
if timeout and time.time() - start_time > timeout / 1000:
return False
time.sleep(0.01)

The tables show the times in seconds.

Linux 64bit debug build (only tested in WSL):

  • ./python -m test -u curses test_pyrepl
  • ./python -m test -u curses test_pyrepl.test_unix_console
test_pyrepl test_unix_console
before 17.7 10.8
after 7.4 0.2

Windows 64bit debug build:

  • python.bat -m test test_pyrepl
  • python.bat -m test test_pyrepl.test_windows_console
test_pyrepl test_windows_console
before 19.1 16.5
after 3.7 1.0

I've marked as skipped news - and think this is also a skip issue?

@pablogsal
Copy link
Member

Awesome! Thanks a lot for the find. Great work 🚀

@pablogsal pablogsal merged commit 815061c into python:main Apr 19, 2025
50 checks passed
@chris-eibl chris-eibl deleted the speedup_test_pyrepl branch April 19, 2025 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip issue skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants