예제 #1
0
def exec_plan_scheduled(clock: Clock, plan: List[Block], state: BDSimState,
                        scheduler: sched.scheduler, scheduled_time: float,
                        start_time: float, tuner_to_update: Optional[Tuner]):
    state.t = scheduled_time - start_time

    # execute the 'ontick' steps for each clock, ie read ADC's output PWM's, send/receive datas
    # for b in clock.blocklist:
    #     # if this block requires inputs, only run .next() the second time this was scheduled.
    #     # this way, its data-dependencies are met before .next() executes
    #     if scheduled_time == start_time and not isinstance(b, SourceBlock):
    #         continue
    #     b._x = b.next()

    # now execute the given plan
    for b in plan:
        if isinstance(b, ClockedBlock):
            b._x = b.next()

        if isinstance(b, SinkBlock):
            b.step()  # step sink blocks
        else:
            # propagate all other blocks
            out = b.output(state.t)
            for (n, ws) in enumerate(b.outports):
                for w in ws:
                    w.end.block.inputs[w.end.port] = out[n]

    # forcibly collect garbage to assist in fps constancy
    # gc.collect()

    # print('after collect()', time.monotonic() - scheduled_time)

    if not state.stop and (state.T is None or state.t < state.T):
        next_scheduled_time: float = scheduled_time + clock.T
        scheduler.enterabs(next_scheduled_time,
                           priority=1,
                           action=exec_plan_scheduled,
                           argument=(clock, plan, state, scheduler,
                                     next_scheduled_time, start_time,
                                     tuner_to_update))

    if tuner_to_update:
        tuner_to_update.update()
예제 #2
0
 def schedule(self, schedule: scheduler):
     """Schedules the Job at the given timestamp"""
     tasks = self.__trigger.task().get(self.__blind)
     schedule.enterabs(self.__trigger.time(), 1, batch, argument=(tasks, ))