adding ncores as a propery
@@ -4,6 +4,7 @@ import importlib
from dataclasses import dataclass
from loguru import logger
from tqdm import tqdm
+import psutil
def _is_ipython_notebook(): # pragma: no cover
@@ -92,7 +93,7 @@ class Settings: # pragma: no cover
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._notebook = None
- self._ncores = None
+ self._ncores = psutil.cpu_count()
@property
def logger_fmt(self):
@@ -143,6 +144,21 @@ class Settings: # pragma: no cover
s += temp
return s
+ def _get_ncores(self):
+ if self._ncores is None:
+ self._ncores = psutil.cpu_count()
+ return self._ncores
+
+ def _set_ncores(self, val):
+ if val is None:
+ val = psutil.cpu_count()
+ elif val > psutil.cpu_count():
+ logger.error('Value is more than the available number of cores')
+ val = psutil.cpu_count()
+ self._ncores = val
+
+ ncores = property(fget=_get_ncores, fset=_set_ncores)
+
def _get_notebook(self):
if self._notebook is None:
self._notebook = _is_ipython_notebook()
