Too many open files #1466

Closed
hankhank opened this Issue Nov 8, 2012 · 4 comments

Projects

None yet

3 participants

@hankhank

Hi,
I'm still seeing IOError: [Errno 24] Too many open files: even though I think the issue was resolved in #798 and #791. Should I still be getting this issue on linux? Is my usage incorrect or is there still an underlying issue?

Info:

Centos 5.8 (Final) - 2.6.18-308.16.1.el5 #1 SMP Tue Oct 2 22:01:37 EDT 2012 i686 i686 i386 GNU/Linux
Python 2.7.3 (default, Nov 1 2012, 08:11:26) - Compiled from source
Matplotlib version = '1.1.1'
version__numpy = '1.4'

Traceback:

Traceback (most recent call last):
  File "voicetest.py", line 702, in <module>
  File "voicetest.py", line 698, in main
  File "voicetest.py", line 106, in controller
  File "voicetest.py", line 649, in run
  File "voicetest.py", line 508, in recordResults
  File "/root/workspaces/voicetest/voiceanalysis.py", line 116, in PlotVoice
  File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 471, in savefig
  File "/usr/local/lib/python2.7/site-packages/matplotlib/figure.py", line 1185, in savefig
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2021, in print_figure
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 474, in print_png
IOError: [Errno 24] Too many open files: 'logs/20121108_175128/test_1011/origcall.png'

Code Snippet:

Gets call many times during runtime. Voice stream hands back 160*s16s for each iteration.

def PlotVoice(voice, prefix, samplefreq=8000.0):
    # Organise the voice stream
    v = []
    for f in voice.voiceStream(-1):
        v.extend(f)

    # Amplitude vs. time
    figure(figsize=(16.0, 10.0))
    subplot(221)
    title('Amplitude vs. Time')
    xlabel('Time (s)')
    ylabel('Amplitude (s16)')
    ylim([-8000, 8000])
    tm = arange(len(v))/samplefreq
    plot(tm, v)

    # Spectragram
    subplot(222)
    title('Spectragram')
    specgram(v)

    # FFT
    subplot(223)
    title('FFT')
    n = len(v) # length of the signal
    k = arange(n)
    T = n/samplefreq
    frq = k/T # two sides frequency range
    frq = frq[range(n/2)] # one side frequency range

    Y = fft(v)/n # fft computing and normalization
    Y = Y[range(n/2)]

    plot(frq,abs(Y),'r') # plotting the spectrum
    xlabel('Freq (Hz)')
    ylabel('|Y(freq)|')

    savefig(prefix)
    close()
@pelson
Matplotlib Developers member

@cgohlke and @mdboom might know more, but I'm not sure the commit 4cb2aaa got back ported to v1.1.1. Are you in a position to try the new v1.2.0 release as I'd expect it to work there.

Sorry to be one of those people who's response is "Ah, yes, fixed in <replace with latest version>.". 😄

@ivanov
Matplotlib Developers member

@hankhank also, do check your ulimit -n and compare it to the number that you get from cat /proc/sys/fs/file-max. If cat /proc/sys/fs/file-max ends up being a bigger number (chances are, it is), you can set a higher number via ulimit -n XXXXX. Read this forum post for more details, or here's a more concise description from the confluence project.

@hankhank

It seems as though the issue is fixed in 1.2.0. Quite easily upgraded to the latest using pip.

Thanks for the help guys

@hankhank hankhank closed this Nov 12, 2012
@pelson
Matplotlib Developers member

Cool. Glad it helped @hankhank . (on the plus side, you get all the cool new features of 1.2.0 too!) 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment