From 7a9853bfe1a094b655bc2923e230d92b81d51efa Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 18 May 2021 20:39:55 +0200 Subject: [PATCH] Fix "Too many open Files" exception --- freqtrade/optimize/hyperopt.py | 4 ++-- tests/optimize/test_hyperopt.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 11a1a36f2..326ae144c 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -271,8 +271,8 @@ class Hyperopt: self.backtesting.strategy.trailing_only_offset_is_reached = \ d['trailing_only_offset_is_reached'] - processed = load(self.data_pickle_file, mmap_mode='r') - + with self.data_pickle_file.open('rb') as f: + processed = load(f, mmap_mode='r') bt_results = self.backtesting.backtest( processed=processed, start_date=self.min_date, diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index f23d5bc9e..b80ede734 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -600,6 +600,7 @@ def test_generate_optimizer(mocker, hyperopt_conf) -> None: mocker.patch('freqtrade.optimize.hyperopt.get_timerange', return_value=(Arrow(2017, 12, 10), Arrow(2017, 12, 13))) patch_exchange(mocker) + mocker.patch.object(Path, 'open') mocker.patch('freqtrade.optimize.hyperopt.load', return_value={'XRP/BTC': None}) optimizer_param = {