Repository navigation
FIX Read LOKY_MAX_MEMORY_LEAK_SIZE at each memory check - #688
megacodes24 wants to merge 2 commits into
Conversation
|
About the codecov/patch failure: I checked locally and the worker-side lines aren’t measured in CI. continuous_integration/runtests.sh installs coverage_subprocess.pth, but COVERAGE_PROCESS_START is never set, so coverage.process_startup() does nothing in the worker processes. Running test_max_memory_leak_size_env_var_changed_in_worker with --cov=loky: as in CI: “No data to combine”, and the whole worker loop (476-583) is reported as missing, including the new lines; Would a separate small PR setting COVERAGE_PROCESS_START in runtests.sh be welcome? It should make the coverage of worker-side code visible in general. |
Follow-up of joblib/joblib#1915. As discussed there, the fix should go to loky first.
LOKY_MAX_MEMORY_LEAK_SIZEwas read once whenloky.process_executorwas imported, so a worker kept the value it started with, even when the variable was changed later inside the worker. As suggested by @stepan-srsen in the issue, the worker now reads it on the fly:_get_max_memory_leak_size()reads the environment variable each time a worker checks its memory usage (at most once per_MEMORY_LEAK_CHECK_DELAY)._MAX_MEMORY_LEAK_SIZEis kept as the default value.Changes:
loky/process_executor.py: add_get_max_memory_leak_size()and use it in the worker memory check and in the recycling warning.tests/test_reusable_executor.py: new test where a first task raises the threshold in the worker's environment, then later tasks leak more than 300 MB, and the worker should not be recycled. It fails before the change and passes after.docs/API.rstandCHANGES.md: updated.docs/API.rst.Limitation: each worker has its own copy of the environment, so changing the variable in the parent process after the workers have started still does not reach them (I tested this in joblib/joblib#1915). Passing it with
env=inget_reusable_executorkeeps working, and the existingtest_max_memory_leak_size_env_varstill passes.Tested on Windows, Python 3.12:
tests/test_reusable_executor.pyandtests/test_process_executor_loky.pypass (131 passed, 7 skipped). pre-commit passes.