[Stackless] Examples with Stackless Python Re: InlineCallback Friendly ?
Andrew Francis
andrewfr_ice at yahoo.com
Fri Apr 18 17:26:52 CEST 2008
Hi Folks:
--- Andrew Francis <andrewfr_ice at yahoo.com> wrote:
[J-P Calderone]
The only kind of dispatcher which is really hostile
towards inlineCallbacks is the kind which is
hostile towards Deferreds in general - ie, one which
requires a return value and does not support
Deferreds.
[A Francis]
Once again Jean-Paul, I find your explanation super
helpful and save me time going down the wrong path.
Starting off from where I left off in the "Adventures"
presentation, here are code snippets showing how to
handle other protocols with Stackless Python and
Twisted.
I am starting to experiment with resources as a part
of prototyping REST support in WS-BPEL. I am also
interested in developing front-ends with Flex.
This is an example with resources adapted from the Abe
Fettig example on page 48 of "Twisted Network
Programming Essentials." I am still getting my feet
wet with resources
class HomePage(resource.Resource):
def doWork(self):
message = """
<html>
<head>
</head>
<body>
Hello World
</body>
</html>
"""
self.request.write(message)
self.request.finish()
def render(self, request):
self.request = request
stackless.tasklet(self.doWork)()
return server.NOT_DONE_YET
and here is one with PyAMF .2
(I remember sketching this one out on a napkin at
PyCon 2008)
class EchoServer(TwistedGateway):
def __init__(self):
super(EchoServer, self).__init__()
self.request = None
return
def __echo__(self, request, deferred, y):
print "=>", request, deferred, y
deferred.callback(y)
def echo(self, request, y):
print "=>", request, y
deferred = defer.Deferred()
stackless.tasklet(self.__echo__)(request,
deferred, y)
return deferred
Cheers,
Andrew
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ToyResource2.py
Type: text/x-python
Size: 947 bytes
Desc: 1677339607-ToyResource2.py
URL: <http://www.stackless.com/pipermail/stackless/attachments/20080418/7763bb7d/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: amfServer2.py
Type: text/x-python
Size: 1391 bytes
Desc: 1218550458-amfServer2.py
URL: <http://www.stackless.com/pipermail/stackless/attachments/20080418/7763bb7d/attachment-0001.py>
More information about the Stackless
mailing list