From e4db9a4699bf14dfc14c9cb029103f13a67ec1ca Mon Sep 17 00:00:00 2001 From: stefanhellander Date: Fri, 20 Oct 2023 20:04:54 +0200 Subject: [PATCH] Cleaning up unrelated changes --- fedn/fedn/network/clients/client.py | 51 ++++++++++++----------------- fedn/fedn/utils/dispatcher.py | 10 ++---- 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/fedn/fedn/network/clients/client.py b/fedn/fedn/network/clients/client.py index f103c28c7..387422660 100644 --- a/fedn/fedn/network/clients/client.py +++ b/fedn/fedn/network/clients/client.py @@ -474,39 +474,27 @@ def _process_training_request(self, model_id): "\t Starting processing of training request for model_id {}".format(model_id)) self.state = ClientState.training - # try: - meta = {} - tic = time.time() - mdl = self.get_model(str(model_id)) - meta['fetch_model'] = time.time() - tic - - inpath = self.helper.get_tmp_path() try: + meta = {} + tic = time.time() + mdl = self.get_model(str(model_id)) + meta['fetch_model'] = time.time() - tic + + inpath = self.helper.get_tmp_path() with open(inpath, 'wb') as fh: fh.write(mdl.getbuffer()) - except FileNotFoundError: - logger.error(f"File {inpath} not found.") - except PermissionError: - logger.error(f"Permission denied for writing to {inpath}.") - except IOError as e: - logger.error(f"An IO error occurred: {e}") - except Exception as e: - logger.error(f"An unexpected error occurred: {e}") - outpath = self.helper.get_tmp_path() - tic = time.time() - # TODO: Check return status, fail gracefully - try: + outpath = self.helper.get_tmp_path() + tic = time.time() + # TODO: Check return status, fail gracefully + self.dispatcher.run_cmd("train {} {}".format(inpath, outpath)) - except Exception as e: - logger.error("Failed to launch training.") - logger.debug(e) - logger.debug(type(e).__name__) - meta['exec_training'] = time.time() - tic - tic = time.time() - out_model = None - try: + meta['exec_training'] = time.time() - tic + + tic = time.time() + out_model = None + with open(outpath, "rb") as fr: out_model = io.BytesIO(fr.read()) @@ -525,9 +513,12 @@ def _process_training_request(self, model_id): os.unlink(outpath+'-metadata') except Exception as e: - logger.error(f"An unexpected error occurred: {e}") - logger.error(type(e).__name__) - # Push model update to combiner server + print("ERROR could not process training request due to error: {}".format( + e), flush=True) + updated_model_id = None + meta = {'status': 'failed', 'error': str(e)} + + # Push model update to combiner server updated_model_id = uuid.uuid4() self.set_model(out_model, str(updated_model_id)) meta['upload_model'] = time.time() - tic diff --git a/fedn/fedn/utils/dispatcher.py b/fedn/fedn/utils/dispatcher.py index 1158a3572..a3aab7d8e 100644 --- a/fedn/fedn/utils/dispatcher.py +++ b/fedn/fedn/utils/dispatcher.py @@ -1,8 +1,7 @@ -import platform - from fedn.utils.process import run_process from fedn.common.log_config import logger + class Dispatcher: """ Dispatcher class for compute packages. @@ -33,18 +32,13 @@ def run_cmd(self, cmd_type): args = cmdsandargs[1:] # shell (this could be a venv, TODO: parametrize) - if platform.system() == "Windows": - shell = ['powershell.exe', '-Command'] - else: - shell = ['/bin/sh', '-c'] + shell = ['/bin/sh', '-c'] # add the corresponding process defined in project.yaml and append arguments from invoked command args = shell + [' '.join(cmd + args)] - logger.debug("Trying to run process {} with args {}".format(cmd, args)) run_process(args=args, cwd=self.project_dir) logger.info('Done executing {}'.format(cmd_type)) except IndexError: message = "No such argument or configuration to run." logger.error(message) - print(message, flush=True)