Exemplo n.º 1
0
 def cancel_jobs(job_ids):
     for job_id in _progress(job_ids, with_progress_bar,
                             "Canceling jobs"):
         cmd = f"{self._cancel_cmd} {job_id}".split()
         returncode = subprocess.run(cmd,
                                     stderr=subprocess.PIPE).returncode
         if returncode != 0:
             warnings.warn(f"Couldn't cancel '{job_id}'.", UserWarning)
Exemplo n.º 2
0
def _delete_old_ipython_profiles(scheduler: BaseScheduler,
                                 with_progress_bar: bool = True) -> None:

    if scheduler.executor_type != "ipyparallel":
        return
    # We need the job_ids because only job_names wouldn't be
    # enough information. There might be other job_managers
    # running.
    pattern = "profile_adaptive_scheduler_"
    profile_folders = glob.glob(os.path.expanduser(f"~/.ipython/{pattern}*"))

    running_job_ids = set(scheduler.queue().keys())
    to_delete = [
        folder for folder in profile_folders
        if not folder.split(pattern)[1] in running_job_ids
    ]

    with ThreadPoolExecutor(256) as ex:
        desc = "Submitting deleting old IPython profiles tasks"
        pbar = _progress(to_delete, desc=desc)
        futs = [ex.submit(shutil.rmtree, folder) for folder in pbar]
        desc = "Finishing deleting old IPython profiles"
        for fut in _progress(futs, with_progress_bar, desc=desc):
            fut.result()