From 1667105e21b41901351c2a2d043a80c53fed804b Mon Sep 17 00:00:00 2001 From: Yann Richet Date: Mon, 15 Jun 2026 14:17:09 +0200 Subject: [PATCH] fix: resolve relative cache:// paths to absolute before spawning threads run_local_calculation() calls os.chdir() in worker threads. Since CWD is process-wide, a relative cache:// URI like cache://my-results/ can silently fail: Path('my-results/').exists() returns False in any thread that happens to run after another thread changed the CWD. Fix: in fzr(), before handing calculators to run_cases_parallel(), resolve any relative cache:// path against original_cwd so that all threads receive an absolute URI and Path(...).exists() is CWD-independent. --- fz/core.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fz/core.py b/fz/core.py index 604955a..c6d944e 100644 --- a/fz/core.py +++ b/fz/core.py @@ -1488,6 +1488,22 @@ def fzr( else: has_input_variables = bool(input_variables) + # Resolve relative cache:// paths to absolute before spawning threads. + # run_local_calculation() calls os.chdir() in worker threads; since CWD is + # process-wide, a relative cache:// path resolved via Path(...).exists() in + # one thread may fail while another thread has changed the CWD. + resolved_calculators = [] + for calc in calculators: + if calc.startswith("cache://"): + cache_rel = calc[8:] + cache_path = Path(cache_rel) + if not cache_path.is_absolute(): + cache_path = Path(original_cwd) / cache_path + resolved_calculators.append(f"cache://{cache_path.resolve()}") + else: + resolved_calculators.append(calc) + calculators = resolved_calculators + # Compile all combinations directly to result directories, then prepare temp directories compile_to_result_directories( input_path, model, input_variables, var_combinations, results_dir