title: OSError: [Errno 24] Too many open files python , ubuntu
body: <p>I'm going to write a python script for loading images from a directory and resizing them, so when I'm loading images from a directory I got this error.</p>
  
  <pre><code>from os import listdir
  from PIL import Image as PImage
  import split_folders
  import os, os.path
  
  
  def loadImages(path):
      imagesList = listdir(path)
      loadedImages = []
      for image in imagesList:
          img = PImage.open(os.path.join(path,image))
          loadedImages.append(img)
      return loadedImages
  
  path = "./Inputs/"
  imgs = loadImages(path)
  
  for img in imgs:
      print(img)
  </code></pre>
  
  <p>Here I got an error "OSError: [Errno 24] Too many open files: '/home/thisuri/Documents/Re-Train_OCR/Inputs/00009690_B543XY65.png'" </p>
  
  <p>Following is trace back;</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/thisuri/Documents/Re-Train_OCR/2.py", line 6, in &lt;module&gt;
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/functions.py", line 221, in imread
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/functions.py", line 136, in get_reader
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/format.py", line 687, in search_read_format
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/format.py", line 195, in can_read
    File "/usr/local/lib/python3.6/dist-packages/imageio/plugins/pillow.py", line 104, in _can_read
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/request.py", line 447, in firstbytes
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/request.py", line 456, in _read_first_bytes
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/request.py", line 344, in get_file
  OSError: [Errno 24] Too many open files: '/home/thisuri/Documents/Re-Train_OCR/Inputs/00009690_B543XY65.png'
  Error in sys.excepthook:
  Traceback (most recent call last):
    File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    File "&lt;frozen importlib._bootstrap&gt;", line 971, in _find_and_load
    File "&lt;frozen importlib._bootstrap&gt;", line 955, in _find_and_load_unlocked
    File "&lt;frozen importlib._bootstrap&gt;", line 665, in _load_unlocked
    File "&lt;frozen importlib._bootstrap_external&gt;", line 674, in exec_module
    File "&lt;frozen importlib._bootstrap_external&gt;", line 780, in get_code
    File "&lt;frozen importlib._bootstrap_external&gt;", line 832, in get_data
  OSError: [Errno 24] Too many open files: '/usr/lib/python3/dist-packages/apport/__init__.py'
  
  Original exception was:
  Traceback (most recent call last):
    File "/home/thisuri/Documents/Re-Train_OCR/2.py", line 6, in &lt;module&gt;
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/functions.py", line 221, in imread
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/functions.py", line 136, in get_reader
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/format.py", line 687, in search_read_format
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/format.py", line 195, in can_read
    File "/usr/local/lib/python3.6/dist-packages/imageio/plugins/pillow.py", line 104, in _can_read
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/request.py", line 447, in firstbytes
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/request.py", line 456, in _read_first_bytes
    File "/usr/local/lib/python3.6/dist-packages/imageio/core/request.py", line 344, in get_file
  OSError: [Errno 24] Too many open files: '/home/thisuri/Documents/Re-Train_OCR/Inputs/00009690_B543XY65.png'
  </code></pre>
  
  <p>How to solve this?</p>