[Moin-devel] deferred and macros

William Waites ww at groovy.net
Tue Dec 21 09:13:24 EST 2004


On Tue, Dec 21, 2004 at 05:37:47PM +0100, Alexander Schremmer wrote:
> 
> So what do you want to do exactly? You want to have a code object which gets
> evaluated on page view?

One application I have in mind is transcluding other pages from other
sites, for example an rss feed.

in pseudo-code:

def _cbFormatRss(page):
    ... do some formatting ...
    return htmlstring

def execute(macro, rssurl):
    return getUrl(rssurl).addCallback(_cbFormatRss)

> > However having macros able to return deferreds is useful since
> > it makes it possible to make many calls to the twisted framework
> > from within MoinMoin. 
> 
> Which exactly?

The above can also be done with regular python modules but another
is more difficult since it is already using twisted: returning status
information from a telephony server (Asterisk + embedded python which
is integrated with twisted via the perspective broker).

> > But it is difficult because right now the
> > MoinMoin architecture expects calls like this to be synchronous
> 
> Between which events do you want your code to be asynchronous?

Between the macro execution and the page rendering.

> > So I'm not sure what my question is. 
> 
> I second that. ;-)

heh ;)

I'm pretty sure that my question is clear actually, I just can't
think of an answer that does not imply fairly major changes to
Moin....

The ugly, kludgy way of doing it would be:

def execute(macro, args):
    from threading import Event
    e = Event()
    ret = []

    def _cbDoStuff(thing):
        ret.append(str(thing))
        e.set()
    def asyncFunction(args):
        getStuff.addCallback(_cbDoStuff)

    from twisted.internet import reactor
    reactor.callInThread(asyncFunction, args)

    e.wait()
    return ret[0]

but that's very, very kludgy

Cheers,
-w




More information about the Moin-devel mailing list