blob: 5834575c7df5006bdeefdb2f7db02f550cb2180c [file] [log] [blame]
Guido van Rossumb31c7f71993-11-11 10:31:23 +00001# Testing select module
Barry Warsaw792c94a1996-12-11 23:58:46 +00002import select
3import os
4
5# test some known error conditions
6try:
7 rfd, wfd, xfd = select.select(1, 2, 3)
8except TypeError:
9 pass
10else:
11 print 'expected TypeError exception not raised'
12
13class Nope:
14 pass
15
16class Almost:
17 def fileno(self):
18 return 'fileno'
19
20try:
21 rfd, wfd, xfd = select.select([Nope()], [], [])
22except TypeError:
23 pass
24else:
25 print 'expected TypeError exception not raised'
26
27try:
28 rfd, wfd, xfd = select.select([Almost()], [], [])
29except TypeError:
30 pass
31else:
32 print 'expected TypeError exception not raised'
33
Guido van Rossumb31c7f71993-11-11 10:31:23 +000034
Guido van Rossumb31c7f71993-11-11 10:31:23 +000035def test():
Barry Warsaw792c94a1996-12-11 23:58:46 +000036 cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
Guido van Rossumb31c7f71993-11-11 10:31:23 +000037 p = os.popen(cmd, 'r')
38 for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
39 print 'timeout =', tout
40 rfd, wfd, xfd = select.select([p], [], [], tout)
Barry Warsaw792c94a1996-12-11 23:58:46 +000041## print rfd, wfd, xfd
Guido van Rossumb31c7f71993-11-11 10:31:23 +000042 if (rfd, wfd, xfd) == ([], [], []):
43 continue
44 if (rfd, wfd, xfd) == ([p], [], []):
45 line = p.readline()
46 print `line`
47 if not line:
48 print 'EOF'
49 break
50 continue
51 print 'Heh?'
52
53test()
Barry Warsaw792c94a1996-12-11 23:58:46 +000054