From: joblack on
I get sometimes a

Errno 9 Bad file descriptor

the code is too long to show it here but what are the circumstances
this could happen? A web search showed nothing.

I have especially the feeling Python 2.6 has some problems with
Unicode ... and might not find the file. Is that possible?
From: Steven D'Aprano on
On Sun, 11 Jul 2010 17:48:40 -0700, joblack wrote:

> I get sometimes a
>
> Errno 9 Bad file descriptor
>
> the code is too long to show it here

You can at least show the actual line that fails. Are you trying to open
a file, a named socket, a pipe or a device?


> but what are the circumstances this
> could happen? A web search showed nothing.

The first two google hits for "bad file descriptor" seem pretty relevant
to me:

http://linux.sys-con.com/node/1053821
http://lists.freebsd.org/pipermail/freebsd-questions/2003-June/009583.html


> I have especially the feeling Python 2.6 has some problems with Unicode
> ... and might not find the file. Is that possible?

Possible, but you should get

Errno 2 No such file or directory

not bad file descriptor.

If you're trying to open a file, you have a broken file system and need
to run fsck or equivalent. If it's a pipe or socket or something, you
need to tell us what it is.



--
Steven
From: Tim Roberts on
joblack <johannes.black(a)gmail.com> wrote:
>
>I get sometimes a
>
>Errno 9 Bad file descriptor
>
>the code is too long to show it here but what are the circumstances
>this could happen? A web search showed nothing.
>
>I have especially the feeling Python 2.6 has some problems with
>Unicode ... and might not find the file. Is that possible?

You seem to be under the mistaken impression that we all have crystal balls
and are able to read your mind. There is SO MUCH you haven't told us here.
Which platform? Surely you can post SOME of the code around where the
error occurs.

For example, there is a bug in the Windows shell that will cause this error
if you try to read stdin when a Python script is called implicitly from a
command line:

C:\tmp>type y.py
import sys

print sys.stdin.readlines()

C:\tmp>y.py < y.py
Traceback (most recent call last):
File "C:\tmp\y.py", line 3, in <module>
print sys.stdin.readlines()
IOError: [Errno 9] Bad file descriptor

C:\tmp>python y.py < y.py
['import sys\n', '\n', 'print sys.stdin.readlines()\n']

C:\tmp>
--
Tim Roberts, timr(a)probo.com
Providenza & Boekelheide, Inc.
From: Cameron Simpson on
On 11Jul2010 17:48, joblack <johannes.black(a)gmail.com> wrote:
| I get sometimes a
|
| Errno 9 Bad file descriptor
|
| the code is too long to show it here but what are the circumstances
| this could happen? A web search showed nothing.
|
| I have especially the feeling Python 2.6 has some problems with
| Unicode ... and might not find the file. Is that possible?

You get a UNIX "bad file descriptor" error when you try to use an
invalid file descriptor number. The typical occasion is when you open a
file, use it, close it, and then try to continue to use it.

I would suspect you have performed that sequence in some way.

But you should really try to produce a small sequence of code that shows
the error. That way you can post it here, and for extra value you may
reduce it to the point where you realise what you have done wrong, since
the failing code is then small enough for you to examine easily.

Cheers,
--
Cameron Simpson <cs(a)zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

There is a chasm
of carbon and silicon
the software can't bridge
- Haiku Error Messages http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html
From: joblack on
Thanks for the answers so far. It's not my code I'm just curious how
that could happen:

Starting point:
....
self.status['text'] = 'Processing ...'
try:
cli_main(argv)
except Exception, e:
self.status['text'] = 'Error: ' + str(e)
return
....
cli_main:

keypath, inpath, outpath = argv[1:]
....
with open(inpath, 'rb') as inf:
serializer = PDFSerializer(inf, keypath)
with open(outpath, 'wb') as outf:
filenr = outf.fileno()
serializer.dump(outf)
return 0

PDFSerializer.dump:

def dump(self, outf):
self.outf = outf
....