Skip to content

Commit

Permalink
Code change to check if any exception was raised in the threads and p…
Browse files Browse the repository at this point in the history
…ropogate it back to parent process.
  • Loading branch information
judyjoseph committed May 27, 2020
1 parent ec4adfe commit 7ab9a5d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ def get_command(self, ctx, cmd_name):
#

# Execute action per NPU instance for multi instance services.
def execute_asic_instance(inst, multi_inst_list, action):
def execute_asic_instance(inst, event, multi_inst_list, action):
for service in multi_inst_list:
try:
click.echo("Executing {} of service {}@{}...".format(action, service, inst))
run_command("systemctl {} {}@{}.service".format(action, service, inst))
except SystemExit as e:
log_error("Failed to execute {} of service {}@{} with error {}".format(action, service, inst, e))
raise
# Set the event object if there is a failure and exception was raised.
event.set()

# Execute action on list of systemd services
def execute_systemctl(list_of_services, action):
Expand Down Expand Up @@ -152,16 +153,22 @@ def execute_systemctl(list_of_services, action):
# With Multi NPU, Start a thread per instance to do the "action" on multi instance services.
if sonic_device_util.is_multi_npu():
threads = []
# Use this event object to co-ordinate if any threads raised exception
e = threading.Event()
kwargs = {'multi_inst_list' : multi_inst_service_list, 'action' : action}
for inst in range(num_asic):
t = threading.Thread(target=execute_asic_instance, args=(inst,), kwargs=kwargs)
t = threading.Thread(target=execute_asic_instance, args=(inst,e), kwargs=kwargs)
threads.append(t)
t.start()

# Wait for all the threads to finish.
for inst in range(num_asic):
threads[inst].join()

# Check if any of the threads have raised exception, if so exit the process.
if e.is_set():
sys.exit(1)

def run_command(command, display_cmd=False, ignore_error=False):
"""Run bash command and print output to stdout
"""
Expand Down

0 comments on commit 7ab9a5d

Please sign in to comment.