Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tempfile library to handle temporal folders #586

Merged
merged 1 commit into from
Jul 6, 2021
Merged

Use tempfile library to handle temporal folders #586

merged 1 commit into from
Jul 6, 2021

Conversation

JAlvarezJarreta
Copy link
Contributor

When running OrthoFinder in a cluster passing the data in an NFS folder, the tests are so fast that sometimes some internal files are still being deleted at the same time shutil.rmtree() is running, raising an error:

Traceback (most recent call last):
  File "/hps/software/users/ensembl/compara/jalvarez/testbench/OrthoFinder_source/orthofinder.py", line 7, in <module>
    main(args)
  File "/hps/software/users/ensembl/compara/jalvarez/testbench/OrthoFinder_source/scripts_of/__main__.py", line 1719, in main
    CheckDependencies(options, prog_caller, files.FileHandler.GetWorkingDirectory1_Read()[0])
  File "/hps/software/users/ensembl/compara/jalvarez/testbench/OrthoFinder_source/scripts_of/__main__.py", line 1310, in CheckDependencies
    elif not prog_caller.TestSearchMethod(dirForTempFiles, options.search_program):
  File "/hps/software/users/ensembl/compara/jalvarez/testbench/OrthoFinder_source/scripts_of/program_caller.py", line 199, in TestSearchMethod
    shutil.rmtree(d)
  File "/hps/software/users/ensembl/compara/shared/pyenv/versions/3.9.5/lib/python3.9/shutil.py", line 718, in rmtree
    _rmtree_safe_fd(fd, path, onerror)
  File "/hps/software/users/ensembl/compara/shared/pyenv/versions/3.9.5/lib/python3.9/shutil.py", line 675, in _rmtree_safe_fd
    onerror(os.unlink, fullname, sys.exc_info())
  File "/hps/software/users/ensembl/compara/shared/pyenv/versions/3.9.5/lib/python3.9/shutil.py", line 673, in _rmtree_safe_fd
    os.unlink(entry.name, dir_fd=topfd)
FileNotFoundError: [Errno 2] No such file or directory: '.nfs491292b75b71b1300002134e'

Since this temporary folder is only meant to be alive for the time of the test(s), I have moved this code inside a context manager using tempfile. This way the system handles the cleanup on its own, and gives the user more control over where the tests are run (via $TMPDIR, for instance).

When running OrthoFinder in a cluster under an NFS folder, the tests are
so fast that sometimes some internal files are still being deleted whilst
`shutil.rmtree()` is running, raising an error:
```
Traceback (most recent call last):
  File "/hps/software/users/ensembl/compara/jalvarez/testbench/OrthoFinder_source/orthofinder.py", line 7, in <module>
    main(args)
  File "/hps/software/users/ensembl/compara/jalvarez/testbench/OrthoFinder_source/scripts_of/__main__.py", line 1719, in main
    CheckDependencies(options, prog_caller, files.FileHandler.GetWorkingDirectory1_Read()[0])
  File "/hps/software/users/ensembl/compara/jalvarez/testbench/OrthoFinder_source/scripts_of/__main__.py", line 1310, in CheckDependencies
    elif not prog_caller.TestSearchMethod(dirForTempFiles, options.search_program):
  File "/hps/software/users/ensembl/compara/jalvarez/testbench/OrthoFinder_source/scripts_of/program_caller.py", line 199, in TestSearchMethod
    shutil.rmtree(d)
  File "/hps/software/users/ensembl/compara/shared/pyenv/versions/3.9.5/lib/python3.9/shutil.py", line 718, in rmtree
    _rmtree_safe_fd(fd, path, onerror)
  File "/hps/software/users/ensembl/compara/shared/pyenv/versions/3.9.5/lib/python3.9/shutil.py", line 675, in _rmtree_safe_fd
    onerror(os.unlink, fullname, sys.exc_info())
  File "/hps/software/users/ensembl/compara/shared/pyenv/versions/3.9.5/lib/python3.9/shutil.py", line 673, in _rmtree_safe_fd
    os.unlink(entry.name, dir_fd=topfd)
FileNotFoundError: [Errno 2] No such file or directory: '.nfs491292b75b71b1300002134e'
```
Since this temporary folder is only meant to be alive for the time of
the test(s), I have moved this code inside a context manager using
`tempfile`. This way you let the system handle the cleanup on its own,
and gives the user more control over where the tests are run.
Copy link
Owner

@davidemms davidemms left a comment

Choose a reason for hiding this comment

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

Hi Jorge, that looks good, thanks!

@davidemms davidemms merged commit 6e0cb25 into davidemms:master Jul 6, 2021
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.

None yet

2 participants