From 751e359624ee32e60618487ae8c85417a7ce4b72 Mon Sep 17 00:00:00 2001 From: Stuart Read Date: Tue, 24 Sep 2024 16:13:03 -0600 Subject: [PATCH] peakfit: Limit multiprocessing to 2 processes during fitting (Fixes #743) Can be overridden with new env var QUASAR_N_PROCESSES=all --- doc/widgets/peakfit.md | 8 ++++++++ orangecontrib/spectroscopy/widgets/owpeakfit.py | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/widgets/peakfit.md b/doc/widgets/peakfit.md index 76bcdbd6d..691cd19ea 100644 --- a/doc/widgets/peakfit.md +++ b/doc/widgets/peakfit.md @@ -103,3 +103,11 @@ Common uses of these constraints would be: - Limiting the *center* position to some range of x values - Setting a minimum *amplitude* to force positive peaks - Setting a maximum *sigma* to exclude unreasonably wide peaks + +Advanced +-------- + +Unlike the majority of widgets, **Peak Fit** uses multiple processes during fitting to improve +responsiveness and performance. By default this is limited to 2 extra processes, but this can be +overridden by setting the environment variable `QUASAR_N_PROCESSES` to the desired number, or `all` +to use the default value returned by `os.cpu_count()`. diff --git a/orangecontrib/spectroscopy/widgets/owpeakfit.py b/orangecontrib/spectroscopy/widgets/owpeakfit.py index f5d99752e..f91d2891c 100644 --- a/orangecontrib/spectroscopy/widgets/owpeakfit.py +++ b/orangecontrib/spectroscopy/widgets/owpeakfit.py @@ -2,6 +2,7 @@ from functools import reduce import concurrent.futures import multiprocessing +import os from lmfit import Parameters, Model from lmfit.model import ModelResult @@ -36,7 +37,9 @@ best_fit_results, pool_initializer, pool_fit, pool_fit2 # number of processes used for computation -N_PROCESSES = None +# Use 2 or less unless overridden by QUASAR_N_PROCESSES +env_proc = os.getenv('QUASAR_N_PROCESSES') +N_PROCESSES = None if env_proc == "all" else int(env_proc) if env_proc else min(2, multiprocessing.cpu_count()) def fit_results_table(output, model_result, orig_data):