Am Sonntag, 05. Oktober 2008 22:01:15 schrieb Dirk Meyer: > > I must confess that I never used this yield-syntax (or kaa notifier, > > for that matter) before, so I may not fully understand what's going > > on here.. > > The yield code is one of our best stuff :) > http://doc.freevo.org/2.0/SourceDoc/Async
I know, and I have repeatedly wrapped my head around coroutine concepts, but this loop was a mystery for me at first: for m in (yield kaa.beacon.query(type='media', media='ignore')): Now that I read it again, let me try to understand it: yield kaa.beacon.query will actually suspend the surrounding function (coroutine), which is possible only because this is in a main() function decorated as coroutine, and this actually runs from kaa.main.run(), so the yield will yield an InProgress object returned by beacon.query to the main loop, which will resume the coroutine using python 2.5's new send() method, passing the result of the InProgress object in for easy consumption by the above construct. Is that about correct? That also means that the loop is actually over a "normal iterable"; the above reminded me a little of the generator expression syntax because of the (), so I thought there were multiple yields. Still, the asynchronously returned iterable may be itself implemented as a coroutine, so without further knowledge/debugging my suspicion that this keeps a db connection open may still be true? Thanks for the link (and the write-up), it was definitely a good read. Two questions: 1) I did not understand this sentence: "Because of this idiom, in Python 2.5 the yield statement will raise an exception if there is one while Python 2.4 continues and raises the exception when calling get_result." What does this want to tell me? This is not about kaa, but about Python, right? What are the implications of this when using kaa.*? 2) MainThreadCallback: Would it make sense to add the sentence "You could also decorate needs_to_be_called_from_main using @kaa.threaded("kaa.MAINTHREAD") as mentioned in the previous section."? Wouldn't that be the preferred way nowadays? BTW: In http://doc.freevo.org/2.0/SourceDoc/KaaBase, the coroutine decorator is still referred to as yield_execution once. Ciao, Hans
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________ Freevo-devel mailing list Freevo-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/freevo-devel