Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/anyio/abc/_tasks.py: 89%
27 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:38 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:38 +0000
1from __future__ import annotations
3from abc import ABCMeta, abstractmethod
4from collections.abc import Awaitable, Callable
5from types import TracebackType
6from typing import TYPE_CHECKING, Any, Protocol, TypeVar, overload
8if TYPE_CHECKING:
9 from .._core._tasks import CancelScope
11T_Retval = TypeVar("T_Retval")
12T_contra = TypeVar("T_contra", contravariant=True)
15class TaskStatus(Protocol[T_contra]):
16 @overload
17 def started(self: TaskStatus[None]) -> None:
18 ...
20 @overload
21 def started(self, value: T_contra) -> None:
22 ...
24 def started(self, value: T_contra | None = None) -> None:
25 """
26 Signal that the task has started.
28 :param value: object passed back to the starter of the task
29 """
32class TaskGroup(metaclass=ABCMeta):
33 """
34 Groups several asynchronous tasks together.
36 :ivar cancel_scope: the cancel scope inherited by all child tasks
37 :vartype cancel_scope: CancelScope
38 """
40 cancel_scope: CancelScope
42 @abstractmethod
43 def start_soon(
44 self,
45 func: Callable[..., Awaitable[Any]],
46 *args: object,
47 name: object = None,
48 ) -> None:
49 """
50 Start a new task in this task group.
52 :param func: a coroutine function
53 :param args: positional arguments to call the function with
54 :param name: name of the task, for the purposes of introspection and debugging
56 .. versionadded:: 3.0
57 """
59 @abstractmethod
60 async def start(
61 self,
62 func: Callable[..., Awaitable[Any]],
63 *args: object,
64 name: object = None,
65 ) -> Any:
66 """
67 Start a new task and wait until it signals for readiness.
69 :param func: a coroutine function
70 :param args: positional arguments to call the function with
71 :param name: name of the task, for the purposes of introspection and debugging
72 :return: the value passed to ``task_status.started()``
73 :raises RuntimeError: if the task finishes without calling
74 ``task_status.started()``
76 .. versionadded:: 3.0
77 """
79 @abstractmethod
80 async def __aenter__(self) -> TaskGroup:
81 """Enter the task group context and allow starting new tasks."""
83 @abstractmethod
84 async def __aexit__(
85 self,
86 exc_type: type[BaseException] | None,
87 exc_val: BaseException | None,
88 exc_tb: TracebackType | None,
89 ) -> bool | None:
90 """Exit the task group context waiting for all tasks to finish."""