Paul Moore wrote:
Traceback (most recent call last):
File "hello.py", line 13, in <module>
main()
File "hello.py", line 7, in main
sys.stdout.flush()
IOError: [Errno 9] Bad file descriptor
(Question - is it *ever* possible for a Unix program to have invalid
file descriptors 0,1 and 2? At startup - I'm assuming anyone who does
os.close(1) knows what they are doing!)
Of course; simply use the >&- pseudo-redirection, which has been a
standard sh feature (later inherited by ksh and bash, but not csh) for
~30 years. The error message is amusing, too:
$ python -c 'print "foo"' >&-
close failed in file object destructor:
Error in sys.excepthook:
Original exception was:
Adding an explicit flush results in a more understandable error message:
Traceback (most recent call last):
File "<string>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com