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
You could also wrap your generator in a decorator that does the
benchmarking for you:
def cobench(name):
def coroutine(func):
def newfunc(*args, **kwargs):
t0 = time.time()
print '[%s:0]: starting' % name
for r in func(*args, **kwargs):
action = 'yielding' if isinstance(r, kaa.InProgress) or
\
r is kaa.NotFinished else
'finished'
print '[%s:%.05f]: %s %s' % (name, time.time()-t0,
action, r)
yield r
return newfunc
return coroutine
Then declare your coroutines:
@kaa.coroutine()
@cobench('ping')
def ping(...):
...
> >> @@ -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?
Whenever you yield a non-InProgress result from a coroutine, the
coroutine is finished with that result and never reentered.
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).
Cheers,
Jason.
------------------------------------------------------------------------------
_______________________________________________
Freevo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-devel