This repository has been archived on 2023-05-12. You can view files and clone it, but cannot push or open issues or pull requests.
aiosched/aiosched/util/debugging.py

245 lines
6.3 KiB
Python

from abc import ABC, abstractmethod
from aiosched.task import Task
from aiosched.context import TaskContext
class BaseDebugger(ABC):
"""
The base for all debugger objects
"""
@abstractmethod
def on_start(self):
"""
This method is called when the event
loop starts executing
"""
return NotImplemented
@abstractmethod
def on_exit(self):
"""
This method is called when the event
loop exits entirely (all tasks completed)
"""
return NotImplemented
@abstractmethod
def on_task_schedule(self, task: Task, delay: float):
"""
This method is called when a new task is
scheduled (not spawned)
:param task: The Task object representing a
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
:param delay: The delay, in seconds, after which
the task will start executing
:type delay: float
"""
return NotImplemented
@abstractmethod
def on_task_spawn(self, task: Task):
"""
This method is called when a new task is
spawned
:param task: The Task object representing a
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
"""
return NotImplemented
@abstractmethod
def on_task_exit(self, task: Task):
"""
This method is called when a task exits
:param task: The Task object representing an
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
"""
return NotImplemented
@abstractmethod
def before_task_step(self, task: Task):
"""
This method is called right before
calling a task's run() method
:param task: The Task object representing an
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
"""
return NotImplemented
@abstractmethod
def after_task_step(self, task: Task):
"""
This method is called right after
calling a task's run() method
:param task: The Task object representing an
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
"""
return NotImplemented
@abstractmethod
def before_sleep(self, task: Task, seconds: float):
"""
This method is called before a task goes
to sleep
:param task: The Task object representing an
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
:param seconds: The amount of seconds the
task wants to sleep
:type seconds: int
"""
return NotImplemented
@abstractmethod
def after_sleep(self, task: Task, seconds: float):
"""
This method is called after a tasks
awakes from sleeping
:param task: The Task object representing an
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
:param seconds: The amount of seconds the
task actually slept
:type seconds: float
"""
return NotImplemented
@abstractmethod
def before_io(self, timeout: float):
"""
This method is called right before
the event loop checks for I/O events
:param timeout: The max. amount of seconds
that the loop will hang when using the select()
system call
:type timeout: float
"""
return NotImplemented
@abstractmethod
def after_io(self, timeout: float):
"""
This method is called right after
the event loop has checked for I/O events
:param timeout: The actual amount of seconds
that the loop has hung when using the select()
system call
:type timeout: float
"""
return NotImplemented
@abstractmethod
def before_cancel(self, task: Task):
"""
This method is called right before a task
gets cancelled
:param task: The Task object representing a
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
"""
return NotImplemented
@abstractmethod
def after_cancel(self, task: Task) -> object:
"""
This method is called right after a task
gets cancelled
:param task: The Task object representing a
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
"""
return NotImplemented
@abstractmethod
def on_exception_raised(self, task: Task, exc: BaseException):
"""
This method is called right after a task
has raised an exception
:param task: The Task object representing a
aiosched Task and wrapping a coroutine
:type task: :class: aiosched.task.Task
:param exc: The exception that was raised
:type exc: BaseException
"""
return NotImplemented
@abstractmethod
def on_context_creation(self, ctx: TaskContext):
"""
This method is called right after a task
context is initialized, i.e. when set_context
in the event loop is called
:param ctx: The context object
:type ctx: TaskContext
:return:
"""
return NotImplemented
@abstractmethod
def on_context_exit(self, ctx: TaskContext):
"""
This method is called right before a task
context is closed, i.e. when close_context
in the event loop is called
:param ctx: The context object
:type ctx: TaskContext
:return:
"""
return NotImplemented
@abstractmethod
def on_io_schedule(self, stream, event: int):
"""
This method is called whenever the
perform_io primitive is called within
the aiosched event loop with the stream
to be registered in the selector and the
chosen event mask
"""
return NotImplemented
@abstractmethod
def on_io_unschedule(self, stream):
"""
This method is called whenever a stream
is unregistered from the loop's I/O selector
"""
return NotImplemented