OLD | NEW |
(Empty) | |
| 1 import os |
| 2 |
| 3 filename = os.tmpnam() |
| 4 print 'filename:', filename |
| 5 |
| 6 fd_out = os.open(filename, os.O_CREAT | os.O_WRONLY) |
| 7 print 'fd_out:', fd_out |
| 8 os.write (fd_out, 'This is a test.\n') |
| 9 os.close(fd_out) |
| 10 print |
| 11 print 'testing read on good fd...' |
| 12 fd_in = os.open (filename, os.O_RDONLY) |
| 13 print 'fd_in:', fd_in |
| 14 while 1: |
| 15 data_in = os.read(fd_in, 1) |
| 16 print 'data_in:', data_in |
| 17 if data_in == '': |
| 18 print 'data_in was empty' |
| 19 break #sys.exit(1) |
| 20 os.close(fd_in) |
| 21 print |
| 22 print |
| 23 print 'testing read on closed fd...' |
| 24 fd_in = os.open ('test_read.py', os.O_RDONLY) |
| 25 print 'fd_in:', fd_in |
| 26 while 1: |
| 27 data_in = os.read(fd_in, 1) |
| 28 print 'data_in:', data_in |
| 29 if data_in == '': |
| 30 print 'data_in was empty' |
| 31 break |
| 32 os.close(fd_in) |
| 33 d = os.read(fd_in, 1) # fd_in should be closed now... |
| 34 if s == '': |
| 35 print 'd is empty. good.' |
OLD | NEW |