Commit 1b96567e authored by Felix Seibert's avatar Felix Seibert
Browse files

changing the error handling when executing lsit of processes

parent a5d0efdf
...@@ -233,7 +233,7 @@ class OSDManager(object): ...@@ -233,7 +233,7 @@ class OSDManager(object):
if self.debug: if self.debug:
print("starting execution of delete replica commands...") print("starting execution of delete replica commands...")
print(str(datetime.datetime.now())) print(str(datetime.datetime.now()))
processes = div_util.run_commands(delete_replica_command_list, max_processes_delete_replica) processes = div_util.run_commands(delete_replica_command_list, max_processes_delete_replica, print_errors=False)
# run and repeat delete commands, until they return no error # run and repeat delete commands, until they return no error
# (if an error is returned for another reason than that one would delete the last complete replica, # (if an error is returned for another reason than that one would delete the last complete replica,
...@@ -273,7 +273,7 @@ class OSDManager(object): ...@@ -273,7 +273,7 @@ class OSDManager(object):
if self.debug: if self.debug:
print("rerunning " + str(len(errored_deletions)) + " commands because replica could not be deleted...") print("rerunning " + str(len(errored_deletions)) + " commands because replica could not be deleted...")
processes = div_util.run_commands(errored_deletions, max_processes_change_policy) processes = div_util.run_commands(errored_deletions, max_processes_change_policy, print_errors=False)
iterations += 1 iterations += 1
if self.debug: if self.debug:
......
...@@ -33,9 +33,24 @@ def command_list_to_single_string(command_list): ...@@ -33,9 +33,24 @@ def command_list_to_single_string(command_list):
return single_string return single_string
def run_commands(commands, max_processes=200): def print_error(finished_process):
print('executing process finished with error:')
print('process: ')
print(str(finished_process[0]))
print('stdout:')
print(str(finished_process[1][0]))
print('stderr:')
print(str(finished_process[1][1]))
'''
execute list of commands in parallel, return list of executions returned with an error
'''
def run_commands(commands, max_processes=200, print_errors=True):
running_processes = set() running_processes = set()
finished_processes = [] errored_processes = []
for command in commands: for command in commands:
started_process = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True) started_process = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
running_processes.add(started_process) running_processes.add(started_process)
...@@ -45,20 +60,29 @@ def run_commands(commands, max_processes=200): ...@@ -45,20 +60,29 @@ def run_commands(commands, max_processes=200):
for running_process in running_processes: for running_process in running_processes:
if running_process.poll() is not None: if running_process.poll() is not None:
difference.add(running_process) difference.add(running_process)
finished_processes.append((running_process.args, finished_process = (running_process.args,
running_process.communicate(), running_process.communicate(),
running_process.returncode)) running_process.returncode)
if finished_process[2] != 0:
errored_processes.append(finished_process)
if print_errors:
print_error(finished_process)
running_processes = running_processes.difference(difference) running_processes = running_processes.difference(difference)
for p in running_processes: for p in running_processes:
p.wait() p.wait()
for finished_process in running_processes: for finished_process in running_processes:
finished_processes.append((finished_process.args, finished_process = (finished_process.args,
finished_process.communicate(), finished_process.communicate(),
finished_process.returncode)) finished_process.returncode)
if finished_process[2] != 0:
return finished_processes errored_processes.append(finished_process)
if print_errors:
print_error(finished_process)
return errored_processes
# return list(map(lambda proc: (proc.args, proc.communicate(), proc.returncode), all_processes)) # return list(map(lambda proc: (proc.args, proc.communicate(), proc.returncode), all_processes))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment