[Tutor] how to get the return value?

Ingo seedseven at home.nl
Sat Mar 4 16:22:47 CET 2006


To make a time lapse video I've been playing with the sched module.
There is one problem I run into, in the code below, how do I get the
returned value t from printtime into main? 


import time
from sched import scheduler

class time_lapse(scheduler):
    
    def time_lapse(self, start_time, stop_time, interval, priority,
action, argument):
        def lapse():
            action(*argument)
            i=self.enter(interval, priority, lapse, ())
            if stop_time:
                if stop_time<self.timefunc():
                    self.cancel(i)
        self.enterabs(start_time, priority, lapse, ())

def printtime(strf=None):
    t=time.time()
    if strf:
        print time.strftime("%Y%m%d_%H%M%S")
    else:
        print time.localtime()
    return t

def main():
    schedule = time_lapse(time.time, time.sleep)
    start=time.time()
    stop=list(time.localtime(start))
    stop[3]=stop[3]+2
    stop=time.mktime(stop)
    
    #schedule.time_lapse(None,None,5,1,printtime,()) #start now, run
forever
    schedule.time_lapse(start,stop,7,0,printtime,(1,))

    schedule.run()


if __name__ == "__main__":
    main()


Ingo



More information about the Tutor mailing list