Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: safely store and close tasks #253

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

EmmmaTech
Copy link

@EmmmaTech EmmmaTech commented Jul 10, 2023

This PR attempts to safely store then close any loose tasks in the code. AnyIO's task groups are used to safely handle tasks all being created to run coroutines (like the dispatcher and shard manager). Closes #190.

for check, future in self._global_wait_for_handlers:
logger.debug("Dispatching to a global wait_for handler")
create_task(self._run_global_wait_for_handler(check, future, event_name, *args))
async with create_task_group() as tg:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont this block until all callbacks have finished running? Because if so, that is going to cause issues.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the task encounters an await statement that requires the task to sleep until something happens, the event loop is then free to work on another task.
AnyIO Docs

It looks like it is blocking. I'm not sure what else to do though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a per-dispatcher task group be created?

nextcore/gateway/shard_manager.py Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
TAG-Epic added a commit that referenced this pull request Jul 16, 2023
This also waits for error handlers.

Conflicts with #253 is to be expected, sorry!
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.

Stop throwing away asyncio.create_task tasks
2 participants