|
78 | 78 | # Maximum number of concurrent CCPP instances per MPI task |
79 | 79 | CCPP_NUM_INSTANCES = 200 |
80 | 80 |
|
81 | | -def execute(cmd, abort = True): |
82 | | - """Runs a local command in a shell. Waits for completion and |
83 | | - returns status, stdout and stderr. If abort = True, abort in |
84 | | - case an error occurs during the execution of the command.""" |
85 | | - |
86 | | - # Set debug to true if logging level is debug |
87 | | - debug = logging.getLogger().getEffectiveLevel() == logging.DEBUG |
88 | | - |
89 | | - logging.debug('Executing "{0}"'.format(cmd)) |
90 | | - p = subprocess.Popen(cmd, stdout = subprocess.PIPE, |
91 | | - stderr = subprocess.PIPE, shell = True) |
92 | | - (stdout, stderr) = p.communicate() |
93 | | - status = p.returncode |
94 | | - if debug: |
95 | | - message = 'Execution of "{0}" returned with exit code {1}\n'.format(cmd, status) |
96 | | - message += ' stdout: "{0}"\n'.format(stdout.decode(encoding='ascii', errors='ignore').rstrip('\n')) |
97 | | - message += ' stderr: "{0}"'.format(stderr.decode(encoding='ascii', errors='ignore').rstrip('\n')) |
98 | | - logging.debug(message) |
99 | | - if not status == 0: |
100 | | - message = 'Execution of command {0} failed, exit code {1}\n'.format(cmd, status) |
101 | | - message += ' stdout: "{0}"\n'.format(stdout.decode(encoding='ascii', errors='ignore').rstrip('\n')) |
102 | | - message += ' stderr: "{0}"'.format(stderr.decode(encoding='ascii', errors='ignore').rstrip('\n')) |
103 | | - if abort: |
104 | | - raise Exception(message) |
105 | | - else: |
106 | | - logging.error(message) |
107 | | - return (status, stdout.decode(encoding='ascii', errors='ignore').rstrip('\n'), |
108 | | - stderr.decode(encoding='ascii', errors='ignore').rstrip('\n')) |
109 | | - |
110 | 81 | def split_var_name_and_array_reference(var_name): |
111 | 82 | """Split an expression like foo(:,a,1:ddt%ngas) |
112 | 83 | into components foo and (:,a,1:ddt%ngas).""" |
|
0 commit comments