put a timeout for a run, specified in the config file

This commit is contained in:
Trung Nguyen
2024-08-25 16:19:52 -05:00
parent 04400e10a8
commit 9f20e5b7f7
2 changed files with 17 additions and 4 deletions

View File

@ -36,6 +36,7 @@
in.bucky-plus-cnt*,
]
timeout: 60
nugget: 1.0
epsilon: 1e-16

View File

@ -720,7 +720,6 @@ def get_lammps_build_configuration(lmp_binary):
launch LAMMPS using the configuration defined in the dictionary config with an input file
TODO:
- generate new reference values if needed
- wrap subprocess with try/catch to handle exceptions
'''
def execute(lmp_binary, config, input_file_name, generate_ref_yaml=False):
cmd_str = ""
@ -728,10 +727,23 @@ def execute(lmp_binary, config, input_file_name, generate_ref_yaml=False):
cmd_str += config['mpiexec'] + " " + config['mpiexec_numproc_flag'] + " " + config['nprocs'] + " "
cmd_str += lmp_binary + " -in " + input_file_name + " " + config['args']
logger.info(f" Executing: {cmd_str}")
p = subprocess.run(cmd_str, shell=True, text=True, capture_output=True)
# set a timeout (in seconds) for each run
timeout = 60
if 'timeout' in config:
if config['timeout'] != "":
timeout = int(config['timeout'])
try:
p = subprocess.run(cmd_str, shell=True, text=True, capture_output=True, timeout=timeout)
return cmd_str, p.stdout, p.stderr, p.returncode
except subprocess.TimeoutExpired:
msg = f" Timeout for {cmd_str} ({timeout} s) expired"
logger.info(msg)
print(msg)
return cmd_str, "", "", -1
'''
split a list into a list of N sublists