Repository navigation
ev: add do_not_call_callbacks loop option for embedders - #593
Conversation
Add a Loop option that makes tick() collect finished standalone completions into a queue (drained via Loop.nextDispatched) instead of invoking their callbacks. This lets a driver run the blocking poll and then invoke callbacks itself at a controlled point. The motivating case is a CPython asyncio event loop built on ev: it can release the GIL around the blocking tick() (which now touches no user callbacks) and reacquire it before draining nextDispatched and calling the callbacks, instead of having callbacks fire from inside tick() where the GIL state is fixed. This is simpler and lower-overhead than acquiring the GIL per callback. The change is confined to finishCompletion: for a standalone (non-rearm, no group owner) completion, push it onto a new state.dispatched queue rather than calling it. Rearm handles and group-owner callbacks are unaffected and still run inline. Default is false, so existing behavior is unchanged.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesDeferred completion dispatch
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Adds a
Loopoptiondo_not_call_callbacks. When set,tick()does the backend poll and all bookkeeping but does not dispatch finished standalone completions to their callbacks — it queues them on a newstate.dispatchedqueue, which the driver drains itself via a newLoop.nextDispatched().Why
The motivating consumer is a CPython
asyncioevent loop built onev. Its callbacks call into CPython and must hold the GIL, but the loop wants to release the GIL around the blocking poll so other Python threads (thread-pool executors, cross-thread wakeups) can run. With this option the driver can:tick()— now Python-free (no callbacks fire),nextDispatched()and call the callbacks itself.This is simpler and lower-overhead than acquiring the GIL per callback from inside
tick()(one release/acquire per loop iteration instead of per callback).Scope
finishCompletion: a standalone (non-rearm, no group owner) completion is pushed tostate.dispatchedinstead of called. Rearm handles and group-owner callbacks are unaffected and still run inline — their machinery must stay synchronous.false, so existing behavior is unchanged.Tests
zig build test— 542/542 pass.