Re: [Tutor] how to get the return value?
Alan Gauld <[EMAIL PROTECTED]> schrijft: > However the real question I have is how you intend to > access that result value. Is it a single value at the end > you want or the cumulative set of values from each > scheduled call? :) Alan, Currently I'm not quite sure what and how I want to do it, so far I've been poking around a bit in the std library to see what options there are to create a sceduling script. Finaly I'd like to be able to have a program do the following, using a "simple" ini_file: for every workingday of a week: from 7.00 until 17.00: every minute: capture a frame and save it at noon: compile a video from the frames gathered this morning do some file manipulations at 17.00: compile a video from the frames gathered this afternoon do some file manipulations on friday 17.00: compile a movie from a selection ( every n_th) of the frames of this week ... The time_lapse function was a first attempt in creating something that starts and stops at a certain time and triggers some actions inbetween. Then I thougth I could use it as the main loop that triggers all the other actions, but then I have to able to change the start and stop times for these from the intial time_lapse loop. Looking at Danny's code, I think a threaded sheduler + shared qeue would be a better approach, but that's something completly new to me. Thanks, Ingo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get the return value?
Anna Ravenscroft <[EMAIL PROTECTED]> schrijft: > On 3/5/06, ingo <[EMAIL PROTECTED]> wrote: > > > > in news:[EMAIL PROTECTED] Kent Johnson wrote: > > [...] > > >>> > > >>>main(printtime(strf=None)) > > >>> > > >>>[...] > > >> > > >> Anna, > > >> > > >> that results in an syntax error / invalid syntax > > > > > > It's very helpful to show the actual error and traceback. > > > > > > > Sorry, here it is: > > > > File "D:\Ingo\PyScript\VIDEOC~1.9\_ij\_time_lapse.py", line 23 > > def main(printtime(strf=None)): > > ^ > > SyntaxError: invalid syntax > > > > Yep. I was suggesting calling printtime as part of your *call* to main, not > when you define main. Sorry to be unclear. >[...] > Hope that makes more sense. > Ah, that makes more sense, I'll play a bit with it, Thanks, Ingo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get the return value?
Danny Yoo <[EMAIL PROTECTED]> schrijft: > But since the scheduler runs in a separate loop than the rest of your > program, trying to return a value between the two won't work very well. > > > However, there are other approaches: we can use some kind of shared > container or communication channel between the main() and the scheduler, > so that they can communicate. > > > One possible way they can communicate is with a shared Queue: > > http://www.python.org/doc/lib/module-Queue.html > > Here is an example that may help: > > ## > from sched import scheduler > import time > from Queue import Queue > from threading import Thread > > > s = scheduler(time.time, time.sleep) > q = Queue() > PRIORITY = 1 > > def f(n): > """Pushes n into the queue, and then reschedules itself with > n+1 to run five seconds later""" > q.put(n) > s.enter(5, PRIORITY, f, (n+1,)) > > ## Let's prime things up. We'll set up the scheduler, and then have > ## it run on its own daemon thread. > s.enter(5, PRIORITY, f, (0,)) > t = Thread(target=s.run) > t.setDaemon(True) > t.start() > > ## At this point, our main thread of execution is separate from the > ## scheduler thread t. > while True: > print "Waiting for event on queue." > print q.get() > ## > > > Does this make sense? Not yet completly Danny, I'll have to study it a bit, but from your use of threads I think you have a better understanding of what I want than I have myself. Thanks, Ingo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor