3

I have a python program, which generates multiple threads that extracts patches corresponding to various organs from set of common image files. It was all fine until I created an extra thread after which I started encountering IO Error 24: Too many open files.

It appears that nibabel framework, which I use to load medical images, leaves the file open. I am unsure if there is anyway I could force the API to close the file after reading.

I request someone to please help me with this, it is fine if I have to use a different framework, but please make sure that it provides an option to close the file after loading it though.

VM_AI
  • 1,132
  • 4
  • 13
  • 25
  • Did you remember to close the files with file.close()? – Ciprum Apr 22 '16 at 18:29
  • I do not understand what you mean by file. If you are on about what object nibabel is returning, then that is not possible since it just returns raw data of that image i.e., matrix. There is no function provided with the API that allows the file to be closed. – VM_AI Apr 22 '16 at 18:55
  • I'm not exactly sure then, but there are duplicate questions. Take a look at them: http://stackoverflow.com/questions/18280612/ioerror-errno-24-too-many-open-files http://stackoverflow.com/questions/26051968/python-2-7-ioerror-errno-24-too-many-open-files – Ciprum Apr 22 '16 at 18:58
  • 1
    @Janekmuric: I have seen that link, my question is specific to python medical image library nibabel, which is not closing the files after reading. – VM_AI Apr 22 '16 at 19:15
  • I am having the same issue - did you ever manage to resolve it? – JDoe2 Dec 19 '20 at 19:47
  • If you use `nib.load`, it has a `kepp_file_open` flag, that you could set to `False` I don't know if that helps you. I get the same error even with the flag. – Pibe_chorro Sep 06 '21 at 12:19
  • I answered a similar question [here](https://stackoverflow.com/questions/49094535/oserror-errno-24-too-many-open-files-using-nibabel/69085145#69085145). Not sure if it solves your multiple thread problem, but it solves the problem of too many open files when reading in a bunch of NIfTI images – Pibe_chorro Sep 07 '21 at 08:56

0 Answers0