From 40312cbcf66d56d037117f8dc6c511b3472980ce Mon Sep 17 00:00:00 2001 From: Pakulin Sergei <38308131+IIaKyJIuH@users.noreply.github.com> Date: Thu, 8 Jun 2023 10:51:59 +0300 Subject: [PATCH] parallel cache files test fix (#1109) --- fedot/core/caching/base_cache_db.py | 2 +- .../cache/test_parallel_cache_files.py | 20 ++++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/fedot/core/caching/base_cache_db.py b/fedot/core/caching/base_cache_db.py index a6cd9a4b87..7268b6db7d 100644 --- a/fedot/core/caching/base_cache_db.py +++ b/fedot/core/caching/base_cache_db.py @@ -24,7 +24,7 @@ def __init__(self, main_table: str = 'default', cache_dir: Optional[str] = None, stats_keys: Sequence = ('default_hit', 'default_total')): self._main_table = main_table self._db_suffix = f'.{main_table}_db' - if cache_dir is None: + if cache_dir is None or Path(cache_dir).samefile(default_fedot_data_dir()): self.db_path = Path(default_fedot_data_dir()) self._del_prev_temps() else: diff --git a/test/integration/cache/test_parallel_cache_files.py b/test/integration/cache/test_parallel_cache_files.py index 151881b9d1..c8abe8c3af 100644 --- a/test/integration/cache/test_parallel_cache_files.py +++ b/test/integration/cache/test_parallel_cache_files.py @@ -1,10 +1,8 @@ -import multiprocessing import sqlite3 -from functools import partial from pathlib import Path -from typing import Callable import psutil +from joblib import Parallel, cpu_count, delayed from examples.simple.classification.api_classification import run_classification_example from examples.simple.regression.api_regression import run_regression_example @@ -12,10 +10,6 @@ from fedot.core.utils import default_fedot_data_dir -def run_example(target: Callable): - target() - - def get_unused_pid() -> int: busy_pids = set(psutil.pids()) for test_pid in range(1, 10000): @@ -34,18 +28,16 @@ def test_parallel_cache_files(): test_file_2.touch() tasks = [ - partial(run_regression_example, with_tuning=False), - partial(run_classification_example, timeout=2., with_tuning=False), - partial(run_ts_forecasting_example, dataset='beer', horizon=10, timeout=2., with_tuning=False), + delayed(run_regression_example)(with_tuning=False), + delayed(run_classification_example)(timeout=1., with_tuning=False), + delayed(run_ts_forecasting_example)(dataset='beer', horizon=10, timeout=1., with_tuning=False), ] - cpus = multiprocessing.cpu_count() + cpus = cpu_count() if cpus > 1: try: - with multiprocessing.Pool(processes=cpus) as pool: - list(pool.imap(run_example, tasks)) + Parallel(n_jobs=cpus)(tasks) except sqlite3.OperationalError: assert False, 'DBs collides' - assert not test_file_1.exists() assert not test_file_2.exists()