Skip to content

clean up open file handles properly#620

Merged
boegel merged 4 commits intoeasybuilders:developfrom
boegel:fix_open_files
Apr 29, 2013
Merged

clean up open file handles properly#620
boegel merged 4 commits intoeasybuilders:developfrom
boegel:fix_open_files

Conversation

@boegel
Copy link
Member

@boegel boegel commented Apr 27, 2013

As became apparent through the easybuild-easyconfigs unit tests as soon as the total number of available easyconfigs passed the magic threshold of 1024, lots of file handles are left dangling in the current framework.
This becomes especially clear when using eb --dep-graph on the full set of available easyconfigs, for example in combination with Python 2.6 since that triggers a bug (http://bugs.python.org/issue3392), see https://jenkins1.ugent.be/view/EasyBuild/job/easybuild-easyconfigs_unit-test_hpcugent_develop/24/testReport/junit/test.easyconfigs.easyconfigs/EasyConfigTest/test_dep_graph/.

This patch fixes the problems, by properly closing open files for /proc/cpuinfo and easyblock log files. Part of the patch is for vsc/utils/fancylogger.py, so this should be fixed in https://github.com/hpcugent/vsc-base instead.

A nice way of pinpointing the source of the growing set of dangling open file handles is posted at http://stackoverflow.com/questions/2023608/check-what-files-are-open-in-python.

@boegel
Copy link
Member Author

boegel commented Apr 27, 2013

I've disabled the easybuild-easyconfigs_unit-test_hpcugent_develop (Python 2.6) test in Jenkins (https://jenkins1.ugent.be/view/EasyBuild) until this gets merged in.

The equivalent tests for Python 2.4 and 2.7 are still active and seem to be robust against lots of open file handles (probably because they lack the bug in Python 2.6 mentioned above, and because the ulimit settings are quite loose). If those tests pass, there should be no issue for Python 2.6 either.

@gribozavr
Copy link
Contributor

It fixes the resource leak in the non-error case, but leaks are still possible in case read() throws.

There should be an exception-safe idiom to read a file in python, given that there were 4 places to fix, we might want a function that just returns the file contents.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a function openread() that does this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created read_file and write_file functions, and used them everywhere. Please rereview (unit tests pass).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note here about not using finally since this is not supported in python 2.4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@JensTimmerman
Copy link

reviewed, ok

boegel added a commit that referenced this pull request Apr 29, 2013
clean up open file handles properly
@boegel boegel merged commit a8c9066 into easybuilders:develop Apr 29, 2013
@boegel boegel deleted the fix_open_files branch April 29, 2013 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants