From 0bccc3e7dcc5f6d3ca0deb48194d22533b8c8a50 Mon Sep 17 00:00:00 2001 From: Valentin Boettcher Date: Thu, 27 Jan 2022 11:21:21 +0100 Subject: [PATCH] do not use context managers for pool because that breaks coverage --- pyproject.toml | 2 +- stocproc/method_ft.py | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0ca0a1e..b56d48e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] description = "Generate continuous time stationary stochastic processes from a given auto correlation function." name = "stocproc" -version = "1.0.3" +version = "1.0.4" authors = ["Richard Hartmann "] license = "BSD (3 clause)" classifiers = [ diff --git a/stocproc/method_ft.py b/stocproc/method_ft.py index 9c2be78..df2542d 100644 --- a/stocproc/method_ft.py +++ b/stocproc/method_ft.py @@ -215,8 +215,14 @@ def _fourier_sum(tau, x, w, f): def fourier_integral_TanhSinh(f, x_max, n, tau_l, t_max_ts): x, w = get_x_w_and_dt(n, x_max, t_max_ts) _f = partial(_fourier_sum, x=x, w=w, f=f) - with Pool() as pool: + + pool = Pool() + try: I = pool.map(_f, tau_l) + finally: + pool.close() + pool.join() + I = np.asarray(I) return I @@ -525,13 +531,23 @@ def get_dt_for_accurate_interpolation(t_max, tol, ft_ref, diff_method=_absDiff): ft_ref_n[::2] = ft_ref_n_old - with Pool() as pool: + pool = Pool() + try: ft_ref_n_new = np.asarray(pool.map(ft_ref, tau[1::2])) + finally: + pool.close() + pool.join() + ft_ref_n[1::2] = ft_ref_n_new ft_intp = fcSpline.FCS(x_low=0, x_high=t_max, y=ft_ref_n_old) - with Pool() as pool: + + pool = Pool() + try: ft_intp_n_new = np.asarray(pool.map(ft_intp, tau[1::2])) + finally: + pool.close() + pool.join() ft_ref_n_new /= ft_ref_0 ft_intp_n_new /= ft_ref_0