Jason Tackaberry wrote: > On Wed, 2009-04-01 at 17:32 +0200, Duncan Webb wrote: >>>> print self.timeit(now)+': pingCo.inprogress=%r' % inprogress >>>> yield inprogress >>>> print self.timeit(now)+': pingCo.inprogress=%r' % inprogress >>>> - yield inprogress.get_result() >>>> + yield inprogress.result >>>> print self.timeit(now)+': pingCo finished' # we never get here >>> Do you ever see the 'print'? I guess yield inprogress.result will just >>> return the result and stop the coroutine. The same is true for other >>> parts of the patch. >> Changing "yield inprogress.result" to "result = inprogress.result" does >> the trick, so now this is shown: >> >> ./freevo --execute=src/tv/record_client.py pingco >> function='pingco' args=[] >> 0.000: pingCo started >> 0.003: pingCo.inprogress=<kaa.async.InProgress object at 0xb68bf74c> >> 0.013: pingCo.inprogress=<kaa.async.InProgress object at 0xb68bf74c> >> 0.015: pingCo finished=True >> 0.019: pingCo=None >> >> This not quite correct as I would like the result of the pingCo to be >> obtained. How do we do this now? > > I admit I don't quite know what you mean, but to the extent I can guess, > why aren't you printing 'finished' _before_ you yield the result: > > print self.timeit(now)+': pingCo.inprogress=%r' % inprogress > yield inprogress > print self.timeit(now)+': pingCo finished=%r' % inprogress.result > yield inprogress.result
Ah thanks yielding the inprogress.result is what I wanted to know. >>>> @@ -179,12 +179,12 @@ >>>> if not inprogress: >>>> return >>>> yield inprogress >>>> - yield inprogress.get_result() >>>> + yield inprogress.result >>>> inprogress = self._recordserver_rpc('findNextProgram') >>>> if not inprogress: >>>> return >>>> yield inprogress >>>> - nextstart = inprogress.get_result() >>>> + nextstart = inprogress.result >>> And this looks wrong. Like above, yield inprogress.result should stop >>> the coroutine. The findNextProgram should never be called. >> >> This is correct findNextProgram is not called. What is the correct way >> to call this; Doing the same as with pingWait does work but may not be >> the best method? > > What are you trying to do? How do you want the coroutine to behave? This is an example of making two rpc calls in a coroutine; the result of the coroutine is the result of the last rpc call. Error handling was not implemented in this example. BTW the coroutines in the record_client are not actually used in freevo-1 but are there to show how to use them and to test the behaviour of coroutines. It is quite tricky to find suitable places in freevo-1 that make a difference to the application. I had to remove one of the few callback methods in the tvguide as it was making the guide behave badly. > Whenever you yield a non-InProgress result from a coroutine, the > coroutine is finished with that result and never reentered. I'm not 100% sure that I get this. Do you mean yielding anything other than the in-progress object causes the coroutine to finish there (like a return in a method)? > The documentation is still in progress (no pun intended), but you might > find it useful to read https://urandom.ca/~tack/kaa/async/ (which is not > a permanent home, just where I happen to have it for testing currently). I'll read through this as it has changed since the earlier versions of the kaa.async package. What would be nice is an example of coroutines in action that shows why someone would want to use them over threads or synchronous code. Thanks, Duncan ------------------------------------------------------------------------------ _______________________________________________ Freevo-devel mailing list Freevo-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/freevo-devel