Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:17

0001 #!/usr/bin/env python
0002 # Licensed under the Apache License, Version 2.0 (the "License");
0003 # you may not use this file except in compliance with the License.
0004 # You may obtain a copy of the License at
0005 # http://www.apache.org/licenses/LICENSE-2.0
0006 #
0007 # Authors:
0008 # - Paul Nilsson, paul.nilsson@cern.ch, 2018
0009 
0010 import os
0011 import sys
0012 
0013 from pilot.util.constants import PILOT_KILL_SIGNAL
0014 from pilot.util.timing import get_time_since
0015 
0016 import logging
0017 logger = logging.getLogger(__name__)
0018 
0019 
0020 def should_abort(args, limit=30, label=''):
0021     """
0022     Abort in case graceful_stop has been set, and less than 30 s has passed since MAXTIME was reached (if set).
0023 
0024     :param args: pilot arguments object.
0025     :param limit: optional time limit (int).
0026     :param label: optional label prepending log messages (string).
0027     :return: True if graceful_stop has been set (and less than optional time limit has passed since maxtime) or False
0028     """
0029 
0030     abort = False
0031     if args.graceful_stop.wait(1) or args.graceful_stop.is_set():  # 'or' added for 2.6 compatibility reasons
0032         if os.environ.get('REACHED_MAXTIME', None) and limit:
0033             # was the pilot killed?
0034             was_killed = was_pilot_killed(args.timing)
0035             time_since = get_time_since('0', PILOT_KILL_SIGNAL, args)
0036             if time_since < limit and was_killed:
0037                 logger.warning('%s:received graceful stop - %d s ago, continue for now' % (label, time_since))
0038             else:
0039                 abort = True
0040         else:
0041             logger.warning('%s:received graceful stop - abort after this iteration' % label)
0042             abort = True
0043 
0044     return abort
0045 
0046 
0047 def was_pilot_killed(timing):
0048     """
0049     Was the pilot killed by a KILL signal?
0050 
0051     :param timing: args.timing dictionary.
0052     :return: Boolean, True if pilot was killed by KILL signal.
0053     """
0054 
0055     was_killed = False
0056     for i in timing:
0057         if PILOT_KILL_SIGNAL in timing[i]:
0058             was_killed = True
0059     return was_killed
0060 
0061 
0062 def is_python3():
0063     """
0064     Check if we are running on Python 3.
0065 
0066     :return: boolean.
0067     """
0068 
0069     return sys.version_info >= (3, 0)