Run executor submissions inline instead of fencing them - #25
Merged
Conversation
run_in_executor no longer fences: the function runs synchronously at an ordinary ready-queue entry labelled executor:<func>, so the seeded draw orders it against everything else and asyncio.to_thread works under simulation. The executor argument is never used, and a future cancelled before its step runs means the function never runs at all. call_soon_threadsafe from the loop's own thread is call_soon, which is all it ever was without a second thread; from any other thread it still fences, since a real thread's timing is outside the simulation. The probe-harness tests lean on add_reader as their canonical fence now.
The contract pages now carry the inline executor: supported-api gains rows for run_in_executor and same-thread call_soon_threadsafe, the fenced list keeps set_default_executor and the cross-thread call, and the README's honest-limits paragraph says executor submissions stay inside the line. design.md keeps its argument against passthrough to a real pool and marks inline execution as the one place the line moved without crossing it. anyio.to_thread is called out for what it is: real worker threads spawned through no loop API, where a fence, a hang or the caller's own timeout is a race between a real thread and a virtual clock.
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.
run_in_executor no longer fences. The submitted function runs synchronously at an ordinary scheduled step — ordered by the seeded draw, labelled
executor:<function>in the trace, costing no virtual time — and its result or exception lands on the returned future the way an executor worker would land it. asyncio.to_thread reaches the loop through this call, so it now works under simulation.What stays honest about it:
design.md keeps its argument against passthrough to a real pool and marks this as the one place the line moved without crossing it. The probe-harness tests lean on add_reader as their canonical fence now that their old one stopped fencing.
Determinism is untouched where it is promised: the submission is a ready-queue entry like any other, a cancelled future means the function never runs, and a trace-hash test pins two runs of the same seed to the same hash.