Skip to content

Commit

Permalink
Cleaning up unrelated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhellander committed Oct 20, 2023
1 parent 25c0227 commit e4db9a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
51 changes: 21 additions & 30 deletions fedn/fedn/network/clients/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions fedn/fedn/utils/dispatcher.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)

0 comments on commit e4db9a4

Please sign in to comment.