From 4289ed0a782cc21aeadd389265979b765319e972 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Tue, 3 Dec 2019 23:13:29 -0600 Subject: [PATCH] Show .err when the job is killed #1323 --- src/sos/tasks.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/sos/tasks.py b/src/sos/tasks.py index 16fe18fb1..80d750bd3 100644 --- a/src/sos/tasks.py +++ b/src/sos/tasks.py @@ -977,16 +977,22 @@ def task_changed(): os.path.expanduser('~'), '.sos', 'tasks', task + '.err') # if the system does not return any error message, write sos-specific one - if not os.path.isfile(syserr_file) or os.path.getsize(syserr_file) == 0: + if os.path.isfile(syserr_file) and os.path.getsize(syserr_file) > 0: + try: + with open(syserr_file) as syserr: + env.logger.warning(''.join(syserr.readlines()[-5:])) + except Exception as e: + env.logger.warning(f'{task} is suspected to be killed but {syserr_file} cannot be read: {e}') + else: soserr_file = os.path.join( os.path.expanduser('~'), '.sos', 'tasks', task + '.soserr') with open(soserr_file, 'a') as err: err.write( f'Task {task} inactive for more than {int(elapsed)} seconds, might have been killed.' ) - env.logger.warning( - f'Task {task} inactive for more than {int(elapsed)} seconds, might have been killed.' - ) + env.logger.warning( + f'Task {task} inactive for more than {int(elapsed)} seconds, might have been killed.' + ) tf.add_outputs() # assume aborted