in dora/run.py [0:0]
def check_job_and_clear(argv: tp.List[str], main: DecoratedMain, clear: bool = False):
"""This will check if an existing job is running and warn,
unless --clear is passed, in which case we must cancel it.
"""
shepherd = Shepherd(main, log)
sheep = shepherd.get_sheep_from_argv(argv)
if sheep.job is not None:
shepherd.update()
if not sheep.is_done():
job = sheep.job
log(red(f"Found existing slurm job {job.job_id} with status {job.state}."))
if clear:
log("Cancelling the existing job.")
shepherd.cancel_lazy(sheep.job)
shepherd.commit()
time.sleep(3)
else:
log(red("PLEASE ABORT NOW UNLESS YOU ARE SURE OF WHAT YOU DO."))
if clear and sheep.xp.folder.exists():
log("Removing existing XP folder.")
try:
rmtree(sheep.xp.folder)
except OSError:
log("Failed to properly remove folder, but things should be okay...")