savefig, too many open files


I have a script to plot and save a sequence of png images which I am using to prepare animations. This works fine, but I got the following error when preparing a particularly large number of files:

— record: 1015
— record: 1016
/usr/lib/python2.5/site-packages/matplotlib/backends/ GtkWarning: Failed to read filechooser settings from “/home/emason/.config/gtk-2.0/gtkfilechooser.ini”: Too many open files

Traceback (most recent call last):
File “”, line 245, in
File “/usr/lib/python2.5/site-packages/matplotlib/”, line 271, in savefig
File “/usr/lib/python2.5/site-packages/matplotlib/”, line 932, in savefig

File “/usr/lib/python2.5/site-packages/matplotlib/”, line 1085, in print_figure
File “/usr/lib/python2.5/site-packages/matplotlib/backends/”, line 103, in print_png

File “/usr/lib/python2.5/site-packages/matplotlib/backends/”, line 303, in print_png
RuntimeError: Could not open file /home/emason/Pictures/movies/cb_3km_emb_vort_1016.png

The script is simple, below I show a pared down version of the loop where the figures are created and saved (but not shown):

for cind in Cind:
P.pcolor(plon, plat, pF[cind])
P.savefig(fname[cind], dpi=150)

Does anybody know why I get this error, and can anything be done about it?

Thanks, Evan