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 resource for possible open number of files #616

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 6 additions & 33 deletions scripts_of/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,46 +1675,19 @@ def CheckOptions(options, speciesToUse):
print("ERROR: Must use '-M msa' option to generate sequence files and infer multiple sequence alignments for orthogroups")
util.Fail()

# check can open enough files
n_extra = 50
# check can open enough files
import resource
n_extra = 100 # as used in util.number_open_files_exception_advice instead of 50
q_do_orthologs = not any((options.qStopAfterPrepare, options.qStopAfterGroups, options.qStopAfterSeqs, options.qStopAfterAlignments, options.qStopAfterTrees))
if q_do_orthologs and not options.qStartFromTrees:
n_sp = len(speciesToUse)
wd = files.FileHandler.GetWorkingDirectory_Write()
wd_files_test = wd + "Files_test/"
fh = []
try:
if not os.path.exists(wd_files_test):
os.mkdir(wd_files_test)
for i_sp in range(n_sp):
di = wd_files_test + "Sp%d/" % i_sp
if not os.path.exists(di):
os.mkdir(di)
for j_sp in range(n_sp):
fnij = di + "Sp%d.txt" % j_sp
fh.append(open(fnij, 'w'))
# create a few extra files to be safe
for i_extra in range(n_extra):
fh.append(open(wd_files_test + "Extra%d.txt" % i_extra, 'w'))
# close the files again and delete
for fhh in fh:
fhh.close()
DeleteDirectoryTree(wd_files_test)
except IOError as e:
if str(e).startswith("[Errno 24] Too many open files"):
u_nfile, sys_nfile = resource.getrlimit(resource.RLIMIT_OFILE)
if (n_sp*n_sp)+n_extra >= u_nfile :
util.number_open_files_exception_advice(len(speciesToUse), False)
for fhh in fh:
fhh.close()
DeleteDirectoryTree(wd_files_test)
util.Fail()
else:
for fhh in fh:
fhh.close()
DeleteDirectoryTree(wd_files_test)
print("ERROR: Attempted to open required files for OrthoFinder run but an unexpected error occurred. \n\nStacktrace:")
raise
return options


def main(args=None):
try:
if args is None:
Expand Down