open() and EOFError

Marko Rauhamaa marko at
Mon Jul 7 18:12:04 CEST 2014

Marko Rauhamaa <marko at>:

> input() quite naturally can raise an IOError. For example:
>     import os, socket
>     s = socket.socket(socket.AF_UNIX)
>     s.bind("xyz")
>     os.dup2(s.fileno(), 0); print(input())
> results in an IOError (EINVAL, to be exact).

Even simpler:

   >>> import os
   >>> os.close(0); input()
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
   IOError: [Errno 9] Bad file descriptor


More information about the Python-list mailing list