LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python "IOError: [Errno 24] Too many open files" (https://www.linuxquestions.org/questions/programming-9/python-ioerror-%5Berrno-24%5D-too-many-open-files-860328/)

Snark1994 02-02-2011 05:45 PM

Python "IOError: [Errno 24] Too many open files"
 
Hi all,

I'm trying to write a mediaplayer for my phone + computer in python... It is going well, but I ran into a problem when I moved the programme from my phone (where it worked) to my computer (where it didn't). The error I got was:
Code:

File "./hearse.py", line 169, in getSongInfo
File "/home/joshua/scripts/python2/myMusic.py", line 120, in getSongTitle
File "/usr/lib64/python2.6/site-packages/mutagen/__init__.py", line 75, in __init__
File "/usr/lib64/python2.6/site-packages/mutagen/mp4.py", line 657, in load
IOError: [Errno 24] Too many open files: '/home/joshua/Music/Billy Joel/Billy Joel CD2/01 My Life.m4a'
Exception KeyboardInterrupt in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored

As you can see, I'm using mutagen to get the metadata for all the files on my computer, and it raises an IOError saying I have too many open files. My thoughts were that this was because my computer has more songs on than my phone, and I had some kind of file descriptor leakage... However, I then redefined the __builtin__.file and __builtin__.open variables so that I could monitor when I was opening and closing files. I also kept a running total of how many files I had open. This total goes between 0 and 1 until the error is raised, which implies to me that I am actually closing all the files I open. Also, it seems that the file that causes the error is the 1011th file - I was wondering whether 1011+stdin+stderr+stdout+file descriptors for curses added up to 1028. But I can't see whether or not that would help find a solution...

Does anyone have any idea why this might be happening? Thanks a lot.


EDIT:
Hm, I thought of running the following line while the programme is still running:
Code:

ls -l /proc/`ps aux | grep hearse | egrep -v grep | awk '{print $2}'`/fd | less
I get a heckuva lot of links pointing to things like "socket:[38657]", with only the number changing. There are also one or two open .mp3 files, strangely... But it seems that there are over 900 of these socket links. They're all coloured red, which I'm guessing means that they're broken links. Again, any clues?

ghostdog74 02-02-2011 06:40 PM

why don't you show what your code looks like?

Snark1994 02-03-2011 06:51 PM

Goodness I feel like a fool... Sorry, I should have done that first :) it was late at night, and I didn't think of doing so. When I started stripping the code down for posting, I discovered the troublesome piece of code - I was asking it to listen to the gstreamer pipeline's bus, but wasn't removing the watcher or disconnecting the bus in my cleanup code for the music player class :)

Well, thanks for the prompting


All times are GMT -5. The time now is 10:31 AM.