image - Python ImageIO: Too many open files -


i using imageio in python in order open video files in directory , convert them numpy arrays.

here script using:

  1 __future__ import print_function   2 avi_to_numpy import *   3 os import listdir   4 import numpy np   5 import imageio    6          7 class_path = '../diving/'   8 max_frames = 16   9 stride = 8  10 videos = [vid vid in listdir(class_path)]  11 train = []  12   13 vid in videos:  14     print(str.format('loading {}...', vid), end="")  15     filename = class_path + vid  16     reader = imageio.get_reader(filename, 'ffmpeg')  17     frames = []  18       19     i, im in enumerate(reader):  20         if len(frames) == max_frames:  21             break  22           23         if % stride == 0:  24             frames.append(im)  25       26     reader.close()  27     train.append(np.array(frames))  28     print('done')          29   30   31 print(len(train)) 

eventually script crashes following error output:

traceback (most recent call last):   file "load_class_test.py", line 16, in <module>     reader = imageio.get_reader(filename, 'ffmpeg')   file "/usr/local/lib/python2.7/site-packages/imageio/core/functions.py", line 111, in get_reader     return format.get_reader(request)   file "/usr/local/lib/python2.7/site-packages/imageio/core/format.py", line 158, in get_reader     return self.reader(self, request)   file "/usr/local/lib/python2.7/site-packages/imageio/core/format.py", line 207, in __init__     self._open(**self.request.kwargs.copy())   file "/usr/local/lib/python2.7/site-packages/imageio/plugins/ffmpeg.py", line 260, in _open     self._initialize()   file "/usr/local/lib/python2.7/site-packages/imageio/plugins/ffmpeg.py", line 326, in _initialize     stdout=sp.pipe, stderr=sp.pipe)   file "/usr/local/cellar/python/2.7.11/frameworks/python.framework/versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__     errread, errwrite)   file "/usr/local/cellar/python/2.7.11/frameworks/python.framework/versions/2.7/lib/python2.7/subprocess.py", line 1223, in _execute_child     errpipe_read, errpipe_write = self.pipe_cloexec()   file "/usr/local/cellar/python/2.7.11/frameworks/python.framework/versions/2.7/lib/python2.7/subprocess.py", line 1175, in pipe_cloexec     r, w = os.pipe() oserror: [errno 24] many open files 

i closing reader object imageio. seems if files opened ffmpeg not being closed properly.

is there obvious step missing here? closing files properly?

edit: found temporary solution. opened new issue on github.

i able resolve issue uncommenting following lines of code 'imageio/plugins/ffmpeg.py':

381         def _close_streams(self): 382             std in (self._proc.stdin, 383                         self._proc.stdout, 384                         self._proc.stderr): 385                 try: 386                     std.close() 387                 except exception:  # pragma: no cover 388                     pass 

i added call above function in _close(self):

271         def _close(self): 272             self._terminate(0.05)  # short timeout 273             self._close_streams() 274             self._proc = none 

i not sure side effects of doing are, provides solution me.

here link issue: https://github.com/imageio/imageio/issues/145


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -