How to use the anyio.TaskGroup function in anyio

To help you get started, we’ve selected a few anyio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Fuyukai / curious / curious / commands / manager.py View on Github external
async def event_hook(self, *args, **kwargs):
        """
        The event hook for the commands manager.
        """
        async with anyio.create_task_group() as tg:
            tg: anyio.TaskGroup
            for (plugin, scope) in self.plugins.values():
                body = inspect.getmembers(plugin, predicate=lambda v: hasattr(v, "is_event"))
                ctx = current_event_context()
                for _, handler in body:
                    if ctx.event_name not in handler.events:
                        continue

                    cofunc = partial(
                        self.client.events._safety_wrapper, handler, ctx, *args, **kwargs
                    )

                    await tg.spawn(cofunc)
github Fuyukai / curious / curious / core / event / manager.py View on Github external
def __init__(self):
        #: The task manager used to spawn events.
        self.task_manager: anyio.TaskGroup = None

        #: A list of event hooks.
        self.event_hooks = set()

        #: A MultiDict of event listeners.
        self.event_listeners = MultiDict()

        #: A MultiDict of temporary listeners.
        self.temporary_listeners = MultiDict()
github Fuyukai / curious / curious / core / client.py View on Github external
self.chunker = md_chunker.Chunker(self)
        self.chunker.register_events(self.events)

        self._ready_state = {}

        #: The :class:`.HTTPClient` used for this bot.
        self.http = HTTPClient(self._token)

        #: The cached gateway URL.
        self._gw_url = None  # type: str

        #: The application info for this bot. Instance of :class:`.AppInfo`.
        self.application_info = None  # type: AppInfo

        #: The task manager used for this bot.
        self.task_manager: anyio.TaskGroup = None

        for (name, event) in scan_events(self):
            self.events.add_event(event)
github Fuyukai / curious / curious / core / event / manager.py View on Github external
async def _wait_for_manager(manager, name: str, predicate):
    """
    Helper class for managing a wait_for.
    """
    async with anyio.create_task_group() as tg:
        tg: anyio.TaskGroup
        try:
            partial = functools.partial(manager.wait_for, name, predicate)
            await tg.spawn(partial)
            yield
        except:
            await tg.cancel_scope.cancel()
            raise
github rmorshea / idom / idom / core / render.py View on Github external
    async def task_group(self) -> AsyncIterator[TaskGroup]:
        async with create_task_group() as group:
            yield group