Skip to content

Commit

Permalink
implement ruff fix
Browse files Browse the repository at this point in the history
  • Loading branch information
esseivaju committed Oct 4, 2024
1 parent 75f3c8e commit ec1d818
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 35 deletions.
46 changes: 22 additions & 24 deletions src/raythena/actors/esworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def check_time(self) -> None:
f"Failed to copy ray logs to actor directory: {e}"
)
if time_elapsed > self.time_limit - self.pilot_kill_time:
killsignal = open(self.pilot_kill_file, "w")
killsignal.close()
with open(self.pilot_kill_file, "w") as f:
f.write("KILL")
self._logger.info("killsignal sent to payload")
break
else:
Expand Down Expand Up @@ -297,23 +297,21 @@ def stagein(self) -> None:
self.payload_actor_process_dir, "ray_logs"
)
try:
time_limit_monitor = open(
os.path.join(self.workdir, self.time_monitor_file)
)
start_time = time_limit_monitor.readline().split(":")
self.start_time = (
int(start_time[0]) * 3600
+ int(start_time[1]) * 60
+ int(start_time[2])
)
time_limit = time_limit_monitor.readline().split(":")
if len(time_limit) < 3:
time_limit = ["0"] + time_limit
self.time_limit = (
int(time_limit[0]) * 3600
+ int(time_limit[1]) * 60
+ int(time_limit[2])
)
with open(os.path.join(self.workdir, self.time_monitor_file)) as time_limit_monitor:
start_time = time_limit_monitor.readline().split(":")
self.start_time = (
int(start_time[0]) * 3600
+ int(start_time[1]) * 60
+ int(start_time[2])
)
time_limit = time_limit_monitor.readline().split(":")
if len(time_limit) < 3:
time_limit = ["0"] + time_limit
self.time_limit = (
int(time_limit[0]) * 3600
+ int(time_limit[1]) * 60
+ int(time_limit[2])
)
timer_thread = threading.Thread(
name="timer", target=self.check_time, daemon=True
)
Expand Down Expand Up @@ -341,15 +339,15 @@ def stagein(self) -> None:
os.mkdir(self.payload_actor_output_dir)
except Exception as e:
self._logger.warning(f"Exception when creating dir: {e}")
raise StageInFailed(self.id)
raise StageInFailed(self.id) from e
# self.cpu_monitor = CPUMonitor(os.path.join(self.payload_actor_process_dir, "cpu_monitor.json"))
# self.cpu_monitor.start()
try:
self.payload.stagein()
self.payload.start(self.modify_job(self.job))
except Exception as e:
self._logger.warning(f"Failed to stagein payload: {e}")
raise StageInFailed(self.id)
raise StageInFailed(self.id) from e
self.transition_state(
ESWorker.READY_FOR_EVENTS
if self.is_event_service_job()
Expand Down Expand Up @@ -426,7 +424,7 @@ def receive_job(self, reply: int, job: PandaJob) -> WorkerResponse:
except BaseRaythenaException:
raise
except Exception as e:
raise WrappedException(self.id, e)
raise WrappedException(self.id, e) from e
else:
self.transition_state(ESWorker.DONE)
self._logger.error("Could not fetch job. Set state to done.")
Expand Down Expand Up @@ -581,7 +579,7 @@ def stageout_event_service_files(
self._logger.error(
f"Failed to move file {cfile} to {dst}: errno {e.errno}: {e.strerror}"
)
raise StageOutFailed(self.id)
raise StageOutFailed(self.id) from e
range_update[cfile_key] = dst
else:
self._logger.warning(
Expand Down Expand Up @@ -669,4 +667,4 @@ def get_message(self) -> WorkerResponse:
except BaseRaythenaException:
raise
except Exception as e:
raise WrappedException(self.id, e)
raise WrappedException(self.id, e) from e
2 changes: 1 addition & 1 deletion src/raythena/actors/payloads/eventservice/pilothttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ async def handle_get_event_ranges(
else:
n_ranges = int(body["nRanges"][0])
if not self.no_more_ranges:
for i in range(n_ranges):
for _ in range(n_ranges):
crange = await self.ranges_queue.get()
if crange is None:
self.no_more_ranges = True
Expand Down
8 changes: 3 additions & 5 deletions src/raythena/drivers/communicators/harvesterMock.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,13 @@ def request_job(self, job_request: PandaJobRequest) -> None:
"SimulationJobOptions/preInclude.BeamPipeKill.py "
"--geometryVersion ATLAS-R2-2016-01-00-00_VALIDATION --physicsList QGSP_BERT "
"--randomSeed 1234 --conditionsTag OFLCOND-MC12-SIM-00 "
"--maxEvents=-1 --inputEvgenFile %s --outputHitsFile HITS_%s.pool.root"
% (self.inFiles, job_name)
f"--maxEvents=-1 --inputEvgenFile {self.inFiles} --outputHitsFile HITS_{job_name}.pool.root"
),
"attemptNr": 0,
"swRelease": "Atlas-21.0.15",
"nucleus": "NULL",
"maxCpuCount": 0,
"outFiles": "HITS_%s.pool.root,%s.job.log.tgz"
% (job_name, job_name),
"outFiles": f"HITS_{job_name}.pool.root,{job_name}.job.log.tgz",
"currentPriority": 1000,
"scopeIn": self.scope,
"PandaID": self.pandaID,
Expand All @@ -261,7 +259,7 @@ def request_job(self, job_request: PandaJobRequest) -> None:
"jobName": job_name,
"ddmEndPointIn": "UTA_SWT2_DATADISK",
"taskID": self.taskId,
"logFile": "%s.job.log.tgz" % job_name,
"logFile": f"{job_name}.job.log.tgz",
}
}
)
8 changes: 3 additions & 5 deletions src/raythena/drivers/communicators/harvesterMock2205.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,13 @@ def request_job(self, job_request: PandaJobRequest) -> None:
"--geometryVersion default:ATLAS-R2-2016-01-00-01_VALIDATION "
"--physicsList FTFP_BERT_ATL_VALIDATION --randomSeed 1234 "
"--conditionsTag default:OFLCOND-MC16-SDR-14 "
"--maxEvents=-1 --inputEvgenFile %s --outputHitsFile HITS_%s.pool.root"
% (self.inFiles, job_name)
f"--maxEvents=-1 --inputEvgenFile {self.inFiles} --outputHitsFile HITS_{job_name}.pool.root"
),
"attemptNr": 0,
"swRelease": "Atlas-22.0.5",
"nucleus": "NULL",
"maxCpuCount": 0,
"outFiles": "HITS_%s.pool.root,%s.job.log.tgz"
% (job_name, job_name),
"outFiles": f"HITS_{job_name}.pool.root,{job_name}.job.log.tgz",
"currentPriority": 1000,
"scopeIn": self.scope,
"PandaID": self.pandaID,
Expand All @@ -135,7 +133,7 @@ def request_job(self, job_request: PandaJobRequest) -> None:
"jobName": job_name,
"ddmEndPointIn": "UTA_SWT2_DATADISK",
"taskID": self.taskId,
"logFile": "%s.job.log.tgz" % job_name,
"logFile": f"{job_name}.job.log.tgz",
}
}
)

0 comments on commit ec1d818

Please sign in to comment.