Skip to content

Commit 5a38820

Browse files
committed
More cleaning
1 parent 5f42a04 commit 5a38820

1 file changed

Lines changed: 25 additions & 27 deletions

File tree

compute_worker/compute_worker.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ def get_folder_size_in_gb(folder):
405405

406406

407407
def delete_files_in_folder(folder):
408+
if not os.path.isdir(folder):
409+
return
408410
for filename in os.listdir(folder):
409411
file_path = os.path.join(folder, filename)
410412
if os.path.isfile(file_path) or os.path.islink(file_path):
@@ -975,15 +977,15 @@ async def _run_program_directory(self, program_dir, kind):
975977
logger.info(f"Metadata path is {os.path.join(program_dir, metadata_path)}")
976978
with open(os.path.join(program_dir, metadata_path), "r") as metadata_file:
977979
try: # try to find a command in the metadata, in other cases set metadata to None
978-
metadata = yaml.load(metadata_file.read(), Loader=yaml.FullLoader)
980+
metadata = yaml.safe_load(metadata_file.read())
979981
logger.info(f"Metadata contains:\n {metadata}")
980982
if isinstance(metadata, dict): # command found
981983
command = metadata.get("command")
982984
else:
983985
command = None
984986
except yaml.YAMLError as e:
985-
logger.error("Error parsing YAML file: ", e)
986-
print("Error parsing YAML file: ", e)
987+
logger.error(f"Error parsing YAML file: {e}")
988+
print(f"Error parsing YAML file: {e}")
987989
command = None
988990
if not command and kind == "ingestion":
989991
raise SubmissionException(
@@ -1227,7 +1229,6 @@ def prepare(self):
12271229
self._update_status(SubmissionStatus.RUNNING, extra_information=f"scoring_hostname-{hostname}")
12281230
else:
12291231
self._update_status(SubmissionStatus.RUNNING, extra_information=f"ingestion_hostname-{hostname}")
1230-
if not self.is_scoring:
12311232
# Only during prediction step do we want to announce "preparing"
12321233
self._update_status(SubmissionStatus.PREPARING)
12331234

@@ -1302,25 +1303,25 @@ def start(self):
13021303
"error_message": error_message,
13031304
"is_scoring": self.is_scoring,
13041305
}
1305-
# Some cleanup
1306-
for kind, logs in self.logs.items():
1307-
containers_to_kill = []
1308-
containers_to_kill.append(self.ingestion_container_name)
1309-
containers_to_kill.append(self.program_container_name)
1310-
logger.debug(
1311-
"Trying to kill and remove container " + str(containers_to_kill)
1312-
)
1313-
for container in containers_to_kill:
1314-
try:
1315-
client.remove_container(str(container), force=True)
1316-
except docker.errors.APIError as e:
1317-
logger.error(e)
1318-
except Exception as e:
1319-
logger.error(
1320-
f"There was a problem killing {containers_to_kill}: {e}"
1321-
)
1322-
if Settings.LOG_LEVEL == Settings.LOG_LEVEL_DEBUG:
1323-
logger.exception(e)
1306+
# Cleanup containers
1307+
containers_to_kill = [
1308+
self.ingestion_container_name,
1309+
self.program_container_name
1310+
]
1311+
logger.debug(
1312+
"Trying to kill and remove container " + str(containers_to_kill)
1313+
)
1314+
for container in containers_to_kill:
1315+
try:
1316+
client.remove_container(str(container), force=True)
1317+
except docker.errors.APIError as e:
1318+
logger.error(e)
1319+
except Exception as e:
1320+
logger.error(
1321+
f"There was a problem killing {containers_to_kill}: {e}"
1322+
)
1323+
if Settings.LOG_LEVEL == Settings.LOG_LEVEL_DEBUG:
1324+
logger.exception(e)
13241325
# Send data to be written to ingestion/scoring std_err
13251326
self._update_submission(execution_time_limit_exceeded_data)
13261327
# Send error through web socket to the frontend
@@ -1390,9 +1391,6 @@ def start(self):
13901391
# set logs of this kind to None, since we handled them already
13911392
logger.info("Program finished")
13921393
signal.alarm(0)
1393-
# Ensure loop is cleaned up
1394-
loop.close()
1395-
asyncio.set_event_loop(None)
13961394

13971395
if self.is_scoring:
13981396
# Check if scoring program failed
@@ -1434,7 +1432,7 @@ def push_scores(self):
14341432
elif os.path.exists(os.path.join(self.output_dir, "scores.txt")):
14351433
scores_file = os.path.join(self.output_dir, "scores.txt")
14361434
with open(scores_file) as f:
1437-
scores = yaml.load(f, yaml.Loader)
1435+
scores = yaml.safe_load(f)
14381436
else:
14391437
raise SubmissionException(
14401438
"Could not find scores file, did the scoring program output it?"

0 commit comments

Comments
 (0)