3.0.ipv8.taskmanager ==================== .. py:module:: 3.0.ipv8.taskmanager Classes ------- .. autoapisummary:: 3.0.ipv8.taskmanager.TaskManager Functions --------- .. autoapisummary:: 3.0.ipv8.taskmanager.task Module Contents --------------- .. py:function:: task(func: Callable) -> Callable Register a TaskManager function as an anonymous task and return the Task object so that it can be awaited if needed. Any exceptions will be logged. Note that if awaited, exceptions will still need to be handled. .. py:class:: TaskManager Provides a set of tools to maintain a list of asyncio Tasks that are to be executed during the lifetime of an arbitrary object, usually getting killed with it. .. py:attribute:: _pending_tasks :type: weakref.WeakValueDictionary[collections.abc.Hashable, asyncio.Future] .. py:attribute:: _shutdown_tasks :type: list[tuple[Callable | collections.abc.Coroutine, tuple[Any, Ellipsis], dict[str, Any]]] :value: [] .. py:attribute:: _task_lock .. py:attribute:: _shutdown :value: False .. py:attribute:: _counter :value: 0 .. py:attribute:: _logger .. py:attribute:: _checker .. py:method:: _check_tasks() -> None .. py:method:: replace_task(name: collections.abc.Hashable, *args: Any, **kwargs) -> asyncio.Future Replace named task with the new one, cancelling the old one in the process. .. py:method:: register_task(name: collections.abc.Hashable, task: Callable | collections.abc.Coroutine | asyncio.Future, *args: Any, delay: float | None = None, interval: float | None = None, ignore: collections.abc.Sequence[type | BaseException] = ()) -> asyncio.Future Register a Task/(coroutine)function so it can be canceled at shutdown time or by name. .. py:method:: register_anonymous_task(basename: str, task: Callable | collections.abc.Coroutine | asyncio.Future, *args: Any, **kwargs) -> asyncio.Future Wrapper for register_task to derive a unique name from the basename. .. py:method:: register_executor_task(name: str, func: Callable, *args: Any, executor: concurrent.futures.ThreadPoolExecutor | None = None, anon: bool = False, **kwargs) -> asyncio.Future Run a synchronous function on the Asyncio threadpool. This function does not work with async functions. .. py:method:: register_shutdown_task(task: Callable | collections.abc.Coroutine, *args: Any, **kwargs) -> None Register a task to be run when this manager is shut down. .. py:method:: cancel_pending_task(name: collections.abc.Hashable) -> asyncio.Future Cancels the named task. .. py:method:: cancel_all_pending_tasks() -> list[asyncio.Future] Cancels all the registered tasks. This usually should be called when stopping or destroying the object so no tasks are left floating around. .. py:method:: is_pending_task_active(name: collections.abc.Hashable) -> bool Return a boolean determining if a task is active. .. py:method:: get_task(name: collections.abc.Hashable) -> asyncio.Future | None Return a task if it exists. Otherwise, return None. .. py:method:: get_tasks() -> list[asyncio.Future] Returns a list of all registered tasks, excluding tasks the are created by the TaskManager itself. .. py:method:: get_anonymous_tasks(base_name: str) -> list[asyncio.Future] Return all tasks with a given base name. Note that this method will return ALL tasks that start with the given base name, including non-anonymous ones. .. py:method:: wait_for_tasks() -> None :async: Waits until all registered tasks are done. .. py:method:: shutdown_task_manager() -> None :async: Clear the task manager, cancel all pending tasks and disallow new tasks being added.