Skip to content

hololinked.core.eventloop.scheduler.QueuedScheduler

Bases: Scheduler

Scheduler class to schedule the operations of a thing in a queued loop.

Source code in repo/hololinked/hololinked/core/eventloop/scheduler.py
class QueuedScheduler(Scheduler):
    """Scheduler class to schedule the operations of a thing in a queued loop."""

    def __init__(self, instance: Thing, eventloop: EventLoop) -> None:
        super().__init__(instance, eventloop)
        self.queue = deque()
        self._one_shot = False
        self._operation_execution_ready_event = CrossLoopEvent()
        self._operation_execution_complete_event = CrossLoopEvent()

    @property
    def has_job(self) -> bool:
        return len(self.queue) > 0

    @property
    def next_job(self) -> Job:
        return self.queue.popleft()

    def dispatch_job(self, job: Job) -> None:
        """
        Append a job to the queue, to be run once everything ahead of it has finished.

        Parameters
        ----------
        job: Job
            the operation to run, and the future that answers whoever submitted it
        """
        # `deque.append` is atomic and the drain loop is the only consumer, so no lock is needed
        # here however many threads submit at once
        self.queue.append(job)
        self._job_queued_event.set()

    def cleanup(self):
        self.queue.clear()
        return super().cleanup()

Functions

__init__

__init__(instance: Thing, eventloop: EventLoop) -> None
Source code in repo/hololinked/hololinked/core/eventloop/scheduler.py
def __init__(self, instance: Thing, eventloop: EventLoop) -> None:
    super().__init__(instance, eventloop)
    self.queue = deque()
    self._one_shot = False
    self._operation_execution_ready_event = CrossLoopEvent()
    self._operation_execution_complete_event = CrossLoopEvent()

dispatch_job

dispatch_job(job: Job) -> None

Append a job to the queue, to be run once everything ahead of it has finished.

Parameters:

Name Type Description Default

job

Job

the operation to run, and the future that answers whoever submitted it

required
Source code in repo/hololinked/hololinked/core/eventloop/scheduler.py
def dispatch_job(self, job: Job) -> None:
    """
    Append a job to the queue, to be run once everything ahead of it has finished.

    Parameters
    ----------
    job: Job
        the operation to run, and the future that answers whoever submitted it
    """
    # `deque.append` is atomic and the drain loop is the only consumer, so no lock is needed
    # here however many threads submit at once
    self.queue.append(job)
    self._job_queued_event.set()

next_job

next_job() -> Job
Source code in repo/hololinked/hololinked/core/eventloop/scheduler.py
@property
def next_job(self) -> Job:
    return self.queue.popleft()

has_job

has_job() -> bool
Source code in repo/hololinked/hololinked/core/eventloop/scheduler.py
@property
def has_job(self) -> bool:
    return len(self.queue) > 0

cleanup

cleanup()
Source code in repo/hololinked/hololinked/core/eventloop/scheduler.py
def cleanup(self):
    self.queue.clear()
    return super().cleanup()