Fix unclosed file descriptors returned by mkstemp

This commit is contained in:
mvdbeek
2020-12-04 18:49:13 +01:00
parent 44518e6a50
commit 53f8215d56
5 changed files with 13 additions and 13 deletions
@@ -34,7 +34,8 @@ def timenow():
def pruneLD(plinktasks=[], cd='./', vclbase=[]):
"""
"""
fplog, plog = tempfile.mkstemp()
fd, plog = tempfile.mkstemp()
os.close(fd)
alog = []
alog.append('## Rgenetics: http://rgenetics.org Galaxy Tools rgQC.py Plink pruneLD runner\n')
for task in plinktasks: # each is a list
+1
View File
@@ -51,6 +51,7 @@ def stream_url_to_file(path, file_sources=None):
if file_sources and file_sources.looks_like_uri(path):
file_source_path = file_sources.get_file_source_path(path)
_, temp_name = tempfile.mkstemp(prefix=prefix)
os.close(_)
file_source_path.file_source.realize_to(file_source_path.path, temp_name)
return temp_name
else:
+2 -3
View File
@@ -357,9 +357,8 @@ def build_maf_index(maf_file, species=None):
indexes, found_species, species_chromosomes, blocks = build_maf_index_species_chromosomes(maf_file, species)
if indexes is not None:
fd, index_filename = tempfile.mkstemp()
out = os.fdopen(fd, 'w')
indexes.write(out)
out.close()
with os.fdopen(fd, 'w') as out:
indexes.write(out)
return (bx.align.maf.Indexed(maf_file, index_filename=index_filename, keep_open=True, parse_e_rows=False), index_filename)
return (None, None)
@@ -80,6 +80,7 @@ class UploadController(BaseUIController):
uploaded_file = None
if valid_url:
fd, uploaded_file_name = tempfile.mkstemp()
os.close(fd)
uploaded_file = open(uploaded_file_name, 'wb')
for chunk in stream.iter_content(chunk_size=util.CHUNK_SIZE):
if chunk:
+7 -9
View File
@@ -25,15 +25,13 @@ def safe_bed_file(infile):
https://lists.soe.ucsc.edu/pipermail/genome/2007-May/013561.html
"""
fix_pat = re.compile("^(track|browser)")
(fd, fname) = tempfile.mkstemp()
in_handle = open(infile)
out_handle = open(fname, "w")
for line in in_handle:
if fix_pat.match(line):
line = "#" + line
out_handle.write(line)
in_handle.close()
out_handle.close()
fd, fname = tempfile.mkstemp()
os.close(fd)
with open(infile) as in_handle, open(fname, 'w') as out_handle:
for line in in_handle:
if fix_pat.match(line):
line = "#" + line
out_handle.write(line)
return fname