Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 1 | # Testing select module |
| 2 | |
| 3 | def test(): |
| 4 | import select |
| 5 | import os |
| 6 | cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do date; sleep 3; done' |
| 7 | p = os.popen(cmd, 'r') |
| 8 | for tout in (0, 1, 2, 4, 8, 16) + (None,)*10: |
| 9 | print 'timeout =', tout |
| 10 | rfd, wfd, xfd = select.select([p], [], [], tout) |
| 11 | print rfd, wfd, xfd |
| 12 | if (rfd, wfd, xfd) == ([], [], []): |
| 13 | continue |
| 14 | if (rfd, wfd, xfd) == ([p], [], []): |
| 15 | line = p.readline() |
| 16 | print `line` |
| 17 | if not line: |
| 18 | print 'EOF' |
| 19 | break |
| 20 | continue |
| 21 | print 'Heh?' |
| 22 | |
| 23 | test() |