Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

"Too Many Files Open" problem

by cr8josh (Acolyte)
on Jan 07, 2012 at 01:19 UTC ( #946696=perlquestion: print w/ replies, xml ) Need Help??
cr8josh has asked for the wisdom of the Perl Monks concerning the following question:

Greetings!

I am using Audio::WAV to both read and write several WAV files through an iterative process. After generating a bunch of files, I get the following:

Background Error: Can't locate C:/Perl64/site/lib/auto/Tk/Error.al: +Too many open files at C:/Perl64/site/lib/Tk.pm line 423

I have checked and I believe I am properly finishing each WAV file I write with write->finish, and in any case the Audio WAV docs specify that finish is "not entirely neccessary as finish is done in DESTROY now (if the file hasn't been finished already)."

I am also reading WAV files iteratively but I don't see any way to close them after reading. I don't know if the 'too many files open' is about reading or writing, but I suspect the former.

Any advice? Many thanks in advance.

Comment on "Too Many Files Open" problem
Download Code
Re: "Too Many Files Open" problem
by Eliya (Vicar) on Jan 07, 2012 at 01:56 UTC

    Maybe you could try handle -p ... to narrow down on what file handles are leaking.

    Also, the error message shows that Tk is involved somehow. Are you sure the Tk part is ok?  Perhaps try running the Audio::WAV code without the GUI (for debugging purposes).

Re: "Too Many Files Open" problem
by Anonymous Monk on Jan 07, 2012 at 02:01 UTC
Re: "Too Many Files Open" problem
by Anonymous Monk on Jan 07, 2012 at 02:43 UTC

    Hi,

    You could try creating the WAV object in a scope that you leave within each iteration. Does that make sense?

    J.C.

Re: "Too Many Files Open" problem
by Marshall (Prior) on Jan 07, 2012 at 04:43 UTC
    It appears to me that you are hitting an OS restriction on open files (not only OS specific, but also installation specific of that OS).

    But in any event it appears that you have too many open file handles - but I guess you know that.

    From Audio::Wav

    use Audio::Wav; my $wav = new Audio::Wav; my $read = $wav -> read( 'input.wav' );
    If you somehow keep track of this $wav object via a reference to it an array of hash or array of array or whatever, I would assume that the file handle to 'input.wav' remains open.

    $wav=undef; would cause that complete object to be destroyed and the file handle freed - right Now! - not when Perl exits.

    Perl will destroy objects upon exit, but sometimes it is necessary to "take control" and do that for yourself. Maybe undef'ing the $read variable is all you need?

    It would be very helpful if you could provide some actual code.

Re: "Too Many Files Open" problem
by ikegami (Pope) on Jan 07, 2012 at 05:38 UTC

    I am also reading WAV files iteratively but I don't see any way to close them after reading.

    Destroy the object returned by read. Do this by losing all references to the object.

Re: "Too Many Files Open" problem
by cr8josh (Acolyte) on Jan 07, 2012 at 06:57 UTC

    THANK YOU ALL!

    I've simplified the code greatly. See below. After 2045 files I get this:

    WAV/j_Wah.wav: unable to open file (Too many open files)

    I used the 'handle' program and indeed the read files are staying open. Any thoughts? Thanks!

    use Audio::Wav; my @wavs = glob ("WAV\/*.wav"); while (1) { for my $wav (@wavs) { print "$wav\n"; my $readwav = new Audio::Wav; my $read = $readwav -> read( "$wav" ); my $src_details = $read -> details(); $readwav = undef; $read = undef; } }

      Hi

      I'd offer a fix, but I'm just so disgusted, report to author :)

      as a workaround you can use      $read->{handle}->close; in your loop

      my  Audio-Wav-0.12\xt\bug.filehandles.t based on your program

        That did it!

        You have my deepest thanks. I spent a long time banging my head against a wall thinking I must be missing something really dumb. I never would have solved this without your help...

Re: "Too Many Files Open" problem
by cavac (Chaplain) on Jan 07, 2012 at 13:26 UTC

    As posted by others, Audio::WAV seems to have a bug.

    If you still run into problems with the number of open files (maybe you actually need to have more open files than permited for whatever you are doing), try this link for Linux or this link for Windows 200/XP/2003 or this link for Windows 7.

    "Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupidů and I went ahead anyway." (Crow in "MST3K The Movie")

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://946696]
Approved by muba
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2014-08-22 11:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (156 votes), past polls