[PEAK] More event questions

Phillip J. Eby pje at telecommunity.com
Fri Nov 12 19:44:58 EST 2004


At 12:11 PM 11/12/04 -0800, Chad Rosenberg wrote:
>What I've got is a method compiled by a cheetah script.  This method is
>called as the result of a Twisted callback.  The cheetah method needs to
>be able to make a PB call to fetch some data and block until the data
>arrives.  Something like this:
>
>-----------
>   def twistedCallback(self):
>       self.callCheetahCompiledMethod()
>
>   ...
>
>   def cheetahCompiledMethod(self):
>       ...
>       print self.utilClass.lookup(foo)
>
>   ...
>
>class UtilClass(binding.Component):
>   def lookup(self, whatToLookup):
>       pbDeferred = self.pbCall(whatToLookup)
>       # Some way to block until results are gotten
>       return results
>-----------
>
>"cheetahCompiledMethod", itself, cannot be asynchronous or use callbacks.
>The call to "lookup" can't be done before "cheetahCompiledMethod" is
>called since it is unknown at that time what "cheetahCompiledMethod" will
>require.  The reason I kept trying to get runUntil to work is it seemed,
>at the time, like a logical choice to block on the PB call in "lookup".
>My heart is not set on nested event loops, but I have yet to figure out
>a way to get the above to work otherwise.  :(

Okay, now I know what you're trying to do.  This actually sounds like a job 
for reactor.callInThread/callFromThread, as I believe would be the normal 
solution in Twisted.

Greenlets are also an option, as is a nested event loop.

For now, I would suggest asking on the Twisted list what the best way to 
handle this within Twisted is.  If you get conflicting or lousy answers, 
then go ahead with the nested loop.

Since your application is tied to Twisted (i.e., won't run without it), you 
can as a kludge simply issue 'reactor.startRunning(False)' following your 
'runUntil()' call, as the simplest way to avoid breaking the outer loop.

I would still like some input from the Twisted folks, though, before I 
enable nested Twisted event loop support in PEAK as a standard feature.




More information about the PEAK mailing list