Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions Lib/test/test_select.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import errno
import os
import select
import subprocess
import sys
import textwrap
import unittest
from test import support

Expand Down Expand Up @@ -45,24 +47,34 @@ def test_returned_list_identity(self):
self.assertIsNot(w, x)

def test_select(self):
cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
with os.popen(cmd) as p:
for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
code = textwrap.dedent('''
import time
for i in range(10):
print("testing...", flush=True)
time.sleep(0.050)
''')
cmd = [sys.executable, '-I', '-c', code]
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc:
pipe = proc.stdout
for timeout in (0, 1, 2, 4, 8, 16) + (None,)*10:
if support.verbose:
print('timeout =', tout)
rfd, wfd, xfd = select.select([p], [], [], tout)
if (rfd, wfd, xfd) == ([], [], []):
print(f'timeout = {timeout}')
rfd, wfd, xfd = select.select([pipe], [], [], timeout)
self.assertEqual(wfd, [])
self.assertEqual(xfd, [])
if not rfd:
continue
if (rfd, wfd, xfd) == ([p], [], []):
line = p.readline()
if rfd == [pipe]:
line = pipe.readline()
if support.verbose:
print(repr(line))
if not line:
if support.verbose:
print('EOF')
break
continue
self.fail('Unexpected return values from select():', rfd, wfd, xfd)
self.fail('Unexpected return values from select():',
rfd, wfd, xfd)

# Issue 16230: Crash on select resized list
def test_select_mutated(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Enhance ``test_select.test_select()``: it now takes 500 ms rather than 10
seconds. Use Python rather than a shell to make the test more portable.