Bugfixes#23
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
Each put_nowait increments _unfinished_tasks. delete_items removed items from the heap without ever decrementing the counter, so queue.join() would block forever if any items were deleted before being consumed. Decrement _unfinished_tasks by the number of deleted items (clamped to the current counter value) and set _finished when the count reaches zero, matching the behaviour of task_done().
_update_timer guarded the timestamp comparison with 'qsize() > 1', so whenever there was exactly one item in the queue it always cancelled and recreated the timer, even if it was already set for the correct time. The qsize check was never load-bearing: the only thing that matters is whether the existing timer is still pending (when() > loop.time()). Drop the condition so the comparison runs for any queue size.
a0184f4 to
cf8c581
Compare
stop() permanently sets the internal asyncio.Event, causing all future iterations to raise StopAsyncIteration immediately. This was undocumented and left no way to reuse a Calendar instance after stopping. Add reset() which clears the event, re-enabling iteration.
The previous approach patched loop.time() with a fixed return_value. Because asyncio.wait_for and call_later both rely on loop.time() for their own scheduling, a constant mock breaks those internals. The test only passed because cq.get() happened to short-circuit before any timeout logic ran. Replace the patch with a direct manipulation of the internal timer: cancel the far-future handle and schedule a new one at delay=0, which fires on the next event loop tick. This simulates the item becoming due without touching asyncio's clock.
Verifies that after stop() is called mid-iteration, further iteration is immediately blocked, and that reset() re-enables the async iterator so remaining scheduled events are emitted correctly.
Signed-off-by: Claudio Usai <claudio.usai@stardustsystems.net>
cf8c581 to
06b50ef
Compare
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.
This PR fixes:
_unfinished_tasksnot being updated after callingdelete_items