【问题标题】:Python OSError: [Errno 24] Too many open filesPython OSError:[Errno 24] 打开的文件太多
【发布时间】:2016-04-21 15:12:59
【问题描述】:

我在 Mac OS 10.11.2 上使用 Ipython Notebook。我运行 Python 3.5.1 和 Matplotlib 1.5.1 和 Seaborn 版本 0.6.0:

%matplotlib inline

import matplotlib.pyplot as plt

import seaborn as sns

我最近开始在使用 Matplotlib/Seaborn 进行绘图时遇到问题。在同一个笔记本中生成几个图后,正在生成我的最新图的笔记本单元崩溃并出现错误:

OSError: [Errno 24] Too many open files: '/Library/Fonts/Arial.ttf'

我仍然可以运行其他单元格,但每次我尝试在此笔记本中绘制某些内容时都会引发相同的错误,直到我重新启动它。

我尝试通过运行来增加文件限制:

sudo launchctl limit maxfiles 10000000 10000000

问题仍然存在,这似乎有所帮助。任何有关如何一劳永逸地解决问题的建议将不胜感激。谢谢 !

以下是错误的确切输出:


OSError                                   Traceback (most recent call last)
/Users/spfraib/anaconda/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)

/Users/spfraib/anaconda/lib/python3.5/site-packages/IPython/core/pylabtools.py in <lambda>(fig)

/Users/spfraib/anaconda/lib/python3.5/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in draw(self)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/figure.py in draw(self, renderer)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/text.py in get_window_extent(self, renderer, dpi)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/text.py in _get_layout(self, renderer)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/mathtext.py in parse(self, s, dpi, prop)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/mathtext.py in __init__(self, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/mathtext.py in __init__(self, *args, **kwargs)

/Users/spfraib/anaconda/lib/python3.5/site-packages/matplotlib/mathtext.py in __init__(self, default_font_prop, mathtext_backend)

OSError: [Errno 24] Too many open files: '/Library/Fonts/Arial.ttf'

【问题讨论】:

    标签: macos python-3.x matplotlib


    【解决方案1】:

    在启动 ipython 之前尝试增加文件限制,例如ulimit -n 4096 最多 4096 个文件描述符。 El Capitan 默认限制为 256 个文件描述符。

    【讨论】:

    • 重启 ipython 后,我尝试了:ulimit -n 4096, ulimit -n 100000。我仍然遇到同样的问题。
    【解决方案2】:

    博客post 中描述的解决方案为我解决了这个问题。我在使用使用 python 驱动的插件系统的 Sublime Text 编辑器时遇到了这些错误。

    使用以下内容创建/Library/LaunchDaemons/limit.maxfiles.plist

    <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"  
            "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">  
      <dict>
        <key>Label</key>
        <string>limit.maxfiles</string>
        <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxfiles</string>
          <string>524288</string>
          <string>524288</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>ServiceIPC</key>
        <false/>
      </dict>
    </plist>  
    

    使用以下内容创建/Library/LaunchDaemons/limit.maxproc.plist

    <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
    <plist version="1.0">
      <dict>
        <key>Label</key>
          <string>limit.maxproc</string>
        <key>ProgramArguments</key>
          <array>
            <string>launchctl</string>
            <string>limit</string>
            <string>maxproc</string>
            <string>2048</string>
            <string>2048</string>
          </array>
        <key>RunAtLoad</key>
          <true />
        <key>ServiceIPC</key>
          <false />
      </dict>
    </plist>
    

    确保权限正确,

    -rw-r--r--   1 root  wheel   541 Oct  5 14:14 limit.maxfiles.plist
    -rw-r--r--   1 root  wheel   586 Oct  5 14:14 limit.maxproc.plist
    

    然后:

    sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
    sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist
    

    起初,它对我不起作用(检查ulimit -a),但在重新启动后,它就像一个魅力。不再有烦人的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-07
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多