Skip to content

drop _current_tasks set; back wait_for_subtasks with count + Event#22

Merged
lesnik512 merged 1 commit intomainfrom
drop-current-tasks-set
May 3, 2026
Merged

drop _current_tasks set; back wait_for_subtasks with count + Event#22
lesnik512 merged 1 commit intomainfrom
drop-current-tasks-set

Conversation

@lesnik512
Copy link
Copy Markdown
Member

The set existed only so wait_for_subtasks could iterate it during graceful shutdown — and it had to re-collect after every gather() to catch tasks added during the wait. Replace it with an int counter and an asyncio.Event that's set when the counter hits zero. wait_for_subtasks becomes a single asyncio.wait_for(event.wait(), timeout=...) call. Tasks added during the wait increment the counter and clear the event, so the wait extends naturally — no re-collect loop needed.

Test rewrite: 9 tests in test_concurrent_processing.py manipulated _current_tasks directly. They now use a small _track_external helper that mirrors handle_task's bookkeeping (increment count + clear event + register the done-callback), so externally-injected tasks still register with wait_for_subtasks.

The set existed only so wait_for_subtasks could iterate it during graceful
shutdown — and it had to re-collect after every gather() to catch tasks
added during the wait. Replace it with an int counter and an asyncio.Event
that's set when the counter hits zero. wait_for_subtasks becomes a single
asyncio.wait_for(event.wait(), timeout=...) call. Tasks added during the
wait increment the counter and clear the event, so the wait extends
naturally — no re-collect loop needed.

Test rewrite: 9 tests in test_concurrent_processing.py manipulated
_current_tasks directly. They now use a small _track_external helper that
mirrors handle_task's bookkeeping (increment count + clear event +
register the done-callback), so externally-injected tasks still register
with wait_for_subtasks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lesnik512 lesnik512 self-assigned this May 3, 2026
@lesnik512 lesnik512 merged commit 22bb38a into main May 3, 2026
5 checks passed
@lesnik512 lesnik512 deleted the drop-current-tasks-set branch May 3, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant