Skip to content

Commit

Permalink
Overwrite the correct part of stderr
Browse files Browse the repository at this point in the history
- Skip partial line
- Seek back to the correct position after readlines()
- Use the same approach in __check_memory_limit()
  • Loading branch information
nsoranzo committed Jun 2, 2016
1 parent ceb825b commit 7cb527a
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/galaxy/jobs/runners/slurm.py
Expand Up @@ -92,8 +92,10 @@ def __get_jobinfo():
with open(ajs.error_file, 'r+') as f:
if os.path.getsize(ajs.error_file) > SLURM_MEMORY_LIMIT_SCAN_SIZE:
f.seek(-SLURM_MEMORY_LIMIT_SCAN_SIZE, os.SEEK_END)
f.readline()
pos = f.tell()
lines = f.readlines()
f.seek(0)
f.seek(pos)
for line in lines:
stripped_line = line.strip()
if any([_ in stripped_line for _ in SLURM_MEMORY_LIMIT_EXCEEDED_PARTIAL_WARNINGS]):
Expand All @@ -114,21 +116,12 @@ def __check_memory_limit( self, efile_path ):
try:
log.debug( 'Checking %s for exceeded memory message from slurm', efile_path )
with open( efile_path ) as f:
pos = 2
bof = False
while pos < 2048:
try:
f.seek(-pos, 2)
pos += 1
except:
f.seek(-pos + 1, 2)
bof = True

if (bof or f.read(1) == '\n') and f.readline().strip() == SLURM_MEMORY_LIMIT_EXCEEDED_MSG:
if os.path.getsize(efile_path) > 2048:
f.seek(-2048, os.SEEK_END)
f.readline()
for line in f.readlines():
if line.strip() == SLURM_MEMORY_LIMIT_EXCEEDED_MSG:
return True

if bof:
break
except:
log.exception('Error reading end of %s:', efile_path)

Expand Down

0 comments on commit 7cb527a

Please sign in to comment.