Repository navigation
Fix deadline cleanup and handling of multiple expired deadlines - #114
Merged
Merged
Conversation
Previously, child tasks spawned inside a deadline scope pushed an inherited DeadlineEntry in Task.__init__ that was never invalidated in Task.close(), leaving valid entries for finished tasks in the scheduler's deadline queue. Additionally, when a deadline expired, Scheduler.tick() only popped entries up to that single oldest timestamp and then blocked unconditionally in get_all(None), even if interrupting those entries produced no ready tasks (e.g. for completed or uninterruptible tasks), which stalled later deadlines until external wakeups drained the queue. This addresses those issues along with related deadline edge cases: - Pop and invalidate all remaining deadlines in Task.close(), and move awaitable.__await__() before push_deadline in Task.__init__. - Clear the task reference in DeadlineEntry.invalidate() (deriving valid from _task is not None) so invalidated entries do not pin finished tasks, and lazily compact the scheduler heap when invalid entries exceed half its size. - Loop in Scheduler._get_ready_tasks() to handle all deadlines <= now via handle_expired_deadlines(), continue waiting for the next deadline if no tasks become ready, avoid starving expired deadlines behind already- ready tasks, and handle interrupt signals without prematurely firing future deadlines.
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.
Previously, child tasks spawned inside a deadline scope pushed an inherited DeadlineEntry in Task.init that was never invalidated in Task.close(), leaving valid entries for finished tasks in the scheduler's deadline queue. Additionally, when a deadline expired, Scheduler.tick() only popped entries up to that single oldest timestamp and then blocked unconditionally in get_all(None), even if interrupting those entries produced no ready tasks (e.g. for completed or uninterruptible tasks), which stalled later deadlines until external wakeups drained the queue.
This addresses those issues along with related deadline edge cases: