diff --git a/pyhdx/config.py b/pyhdx/config.py index 0794320f..6ddec203 100644 --- a/pyhdx/config.py +++ b/pyhdx/config.py @@ -68,6 +68,13 @@ def assets_dir(self) -> Path: return assets_dir + @property + def log_dir(self) -> Path: + spec_path = self.conf.server.log_dir + log_dir = Path(spec_path.replace("~", str(Path().home()))) + + return log_dir + @property def TORCH_DTYPE(self) -> Union[torch.float64, torch.float32]: dtype = self.conf.fitting.dtype @@ -125,4 +132,4 @@ def valid_config() -> bool: cfg = PyHDXConfig() -cfg.set_config(conf) \ No newline at end of file +cfg.set_config(conf) diff --git a/pyhdx/config.yaml b/pyhdx/config.yaml index bf4049c3..0dbb6753 100644 --- a/pyhdx/config.yaml +++ b/pyhdx/config.yaml @@ -4,6 +4,7 @@ cluster: server: assets_dir: ~/.pyhdx/assets + log_dir: ~/.pyhdx/logs fitting: dtype: float64 @@ -25,4 +26,4 @@ plotting: dG_aspect: 2.5 linear_bars_aspect: 30 loss_aspect: 2.5 - rainbowclouds_aspect: 4 \ No newline at end of file + rainbowclouds_aspect: 4 diff --git a/pyhdx/local_cluster.py b/pyhdx/local_cluster.py index e1304446..1608b31f 100644 --- a/pyhdx/local_cluster.py +++ b/pyhdx/local_cluster.py @@ -1,11 +1,13 @@ from __future__ import annotations import argparse +import asyncio import time from asyncio import Future from typing import Callable, Iterable, Any from dask.distributed import LocalCluster, Client +from distributed import connect from pyhdx.config import cfg from pyhdx.support import select_config @@ -75,12 +77,22 @@ def default_cluster(**kwargs): def verify_cluster(scheduler_address, timeout="2s"): """Check if a valid dask scheduler is running at the provided scheduler_address""" try: - client = Client(scheduler_address, timeout=timeout) + asyncio.run(connect(scheduler_address, timeout=timeout)) return True - except (TimeoutError, IOError): + except (TimeoutError, OSError): + return False + + +def verify_cluster_async(scheduler_address, timeout="2s"): + """Check if a valid dask scheduler is running at the provided scheduler_address""" + try: + asyncio.run(connect(scheduler_address, timeout=timeout)) + return True + except (TimeoutError, OSError): return False + def blocking_cluster(): """Start a dask LocalCluster and block until iterrupted""" parser = argparse.ArgumentParser(description="Start a new Dask local cluster") diff --git a/pyhdx/web/serve.py b/pyhdx/web/serve.py index 6bdd0357..2f3e938b 100644 --- a/pyhdx/web/serve.py +++ b/pyhdx/web/serve.py @@ -24,17 +24,18 @@ def run_apps(): np.random.seed(43) torch.manual_seed(43) - scheduler_address = cfg.cluster.scheduler_address - if not verify_cluster(scheduler_address): - print( - f"No valid Dask scheduler found at specified address: '{scheduler_address}'" - ) + # Checking clusters like this interferes with starting the server somehow + # scheduler_address = cfg.cluster.scheduler_address + # if not verify_cluster(scheduler_address): + # print( + # f"No valid Dask scheduler found at specified address: '{scheduler_address}'" + # ) - log_root_dir = Path.home() / ".pyhdx" / "logs" + log_root_dir = cfg.log_dir log_dir = log_root_dir / datetime.datetime.now().strftime("%Y%m%d") log_dir.mkdir( parents=True, exist_ok=True - ) # catch error when log dir does not exist + ) root_log = logging.getLogger("pyhdx") root_log.setLevel(logging.DEBUG)