Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80734

Re: Bad file descriptor

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: Bad file descriptor
Date 2014-11-13 19:41 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-050828.19405213112014@news.panix.com> (permalink)
References <442861d9-4280-4222-9084-f626a7782161@googlegroups.com> <mailman.15802.1415923204.18130.python-list@python.org>

Show all headers | View raw


In article <mailman.15802.1415923204.18130.python-list@python.org>,
 Ben Finney <ben+python@benfinney.id.au> wrote:

> satishmlmlml@gmail.com writes:
> 
> > import os
> > os.write(1, b'Hello descriptor world\n')
> > OSError: Bad file descriptor
> 
> It works fine for me::
> 
>     >>> import os
>     >>> os.write(1, b'Hello descriptor world\n')
>     Hello descriptor world
>     23
> 
> You don't say which Python, or which version, you're using. In the
> absence of different information, most of us will assume the latest
> stable release of CPython. Currently, that is CPython 3.4.

I don't think this has anything to do with which version of Python he's 
using.  I think all that's happening is (for some unknown reason), fd 1 
is closed before his program runs.  You can demonstrate this, for 
example, in bash:


$ cat hello.py 
import os
os.write(1, b'Hello descriptor world\n')


$ python hello.py 
Hello descriptor world


$ 1<&- python hello.py 
Traceback (most recent call last):
  File "hello.py", line 2, in <module>
    os.write(1, b'Hello descriptor world\n')
OSError: [Errno 9] Bad file descriptor


You owe the Oracle 5 minutes of his life back and a cookie for making 
him read enough of the bash manual to figure out the syntax to tell it 
to close a descriptor.

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Bad file descriptor satishmlmlml@gmail.com - 2014-11-13 15:40 -0800
  Re: Bad file descriptor sohcahtoa82@gmail.com - 2014-11-13 15:43 -0800
  Re: Bad file descriptor Ben Finney <ben+python@benfinney.id.au> - 2014-11-14 10:56 +1100
    Re: Bad file descriptor Roy Smith <roy@panix.com> - 2014-11-13 19:41 -0500
  Re: Bad file descriptor Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-14 05:17 +0000
  Re: Bad file descriptor Cameron Simpson <cs@zip.com.au> - 2014-11-14 18:42 +1100

csiph-web