Skip to content

sched behavior causes offset #15

Description

@jbmelander

SharedPixmap load_stream method schedules frames between 0 and duration. If the protocol has any pre_time, this causes the s.run call to take place pre_time into the schedule. Example:

from multiprocessing import shared_memory
import numpy as np
import time
import sched
import threading

class SchedTest:
    def __init__(self, dur, nominal_frame_rate):
        self.dur = dur
        self.nominal_frame_rate = nominal_frame_rate
        self.frameno = 0
        self.load_stream()
    def close(self):
        self.thread.join()
    def genframe(self):
        print('--- frame number {} at {} seconds'.format(self.frameno, time.time()-self.t))
        self.frameno += 1
    def load_stream(self):
        self.s = sched.scheduler(time.time, time.sleep)
        tis = np.arange(0,self.dur,1/self.nominal_frame_rate)
        tis = tis[1:]
        for ti in tis: 
            self.s.enter(ti, 1, self.genframe)
        self.thread = threading.Thread(target=self.s.run)
    def start_stream(self):
        print('-- starting stream')
        self.t = time.time()
        self.thread.start()

if __name__ == '__main__':
    st = SchedTest(10, 2)
    print('Beginning sleep...')
    time.sleep(5)
    print('Finished sleep...')
    st.start_stream()
    st.close()
    print('Finished test')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions