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