Repository navigation
Tell the points still running when an AsyncRunner reaches its goal - #514
Merged
basnijholt merged 2 commits intoDec 6, 2026
Merged
Conversation
python-adaptive#320 made BlockingRunner wait for the points the executor is still computing when the goal is reached and tell their results (python-adaptive#319). AsyncRunner got its futures from run_in_executor, and cancelling such a future marks it cancelled at once even when the executor is already running the point, so the evaluation finished in the worker and was dropped. Submit to the executor directly, keep its future, and when the goal is reached cancel only the points that are still queued and tell the running ones. cancel() and errors still stop at once.
Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>
basnijholt
approved these changes
Dec 6, 2026
basnijholt
left a comment
Member
There was a problem hiding this comment.
Thanks for fixing #319 for AsyncRunner, this is a clean and well-tested improvement!
I pushed a small follow-up commit (d61bba6) to drain _tell_running_points incrementally with asyncio.FIRST_COMPLETED instead of waiting for ALL_COMPLETED, so already-finished points are told immediately (and preserved if runner.cancel() is called during the drain) and fatal errors surface without waiting on slower running points. I also switched the cancellation tests to threading.Event gates and clarified the goal docstring note for time-based goals and shutdown_executor=True.
Looks great to merge once CI is green!
3 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
#319 noticed that the runners threw away the points that were still being computed when the goal was reached, and #320 fixed that for
BlockingRunner: it waits for them and tells the learner.AsyncRunnerstill drops them. As found in #319, it gets anasynciofuture fromrun_in_executor, and cancelling that future marks it cancelled at once, even when the executor's own future is already running and cannot be stopped. The evaluation then finishes in the worker and its result is discarded.With the default executor (loky),
npoints_goal=20,ntasks=4and evaluations of 0.3 to 0.9 s, 3 runs each:mainSo on
mainabout one evaluation in eight of that run was computed for nothing. The extra 0.6 s is the wait for those three points.AsyncRunner._submitnow does whatrun_in_executordoes (executor.submitandasyncio.wrap_future), but keeps the executor's future. When the goal is reached,_runcancels the points that are still queued in the executor and waits for the ones it is already computing, then tells their results, asBlockingRunnerdoes.runner.cancel()and errors still stop at once, without waiting: a cancel means "stop now", and a running evaluation can take hours. A cancel that arrives during the wait also stops it at once. For anasync deffunction nothing changes, because cancelling its task really stops it.The
goalentry of theAsyncRunnerdocstring says so.Tests in
test_runner.py:test_points_running_at_the_goal_are_told, forBlockingRunnerandAsyncRunner: the upper bound takes 0.5 s and is still running whennpoints_goal=10is reached. It must end up inlearner.data, with every evaluation that ran told and nothing pending. OnmaintheAsyncRunnercase fails, andBlockingRunnerpasses since call self._process_futures on canceled futures when BlockingRunner is done #320.test_cancel_does_not_wait_for_running_points:cancel()while a 3 s evaluation is running returns within 1.5 s with statuscancelled. This passes onmaintoo. It guards the choice above.Run here (macOS, on
mainat 2507701):nox -e pytest_min_deps-3.12 pytest_all_deps-3.12 pytest_min_deps-3.13 pytest_all_deps-3.13 pytest_typeguard pytest_rust_backendall pass (3.11 and 3.14 are not installed here), andpre-commit run --all-filespasses, mypy included.Checklist
pre-commit run --all(first install usingpip install pre-commit)pytestpassedType of change