File: stackless.py

package info (click to toggle)
pyamf 0.6.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,692 kB
  • sloc: python: 17,944; xml: 455; makefile: 116; sql: 38; java: 11; sh: 7
file content (41 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import stackless

from   twisted.web import resource, http, server, error
from   twisted.internet import reactor
from   twisted.python import log

from   pyamf import remoting
from   pyamf.remoting.gateway.twisted import TwistedGateway
from   twisted.internet import defer
from   twisted.internet import task


class EchoServer(TwistedGateway):

   def __init__(self):
       super(EchoServer, self).__init__()
       self.request = None
       return

   def __echo__(self, request, deferred, y):
       deferred.callback(y)

   def echo(self, request, y):
       deferred = defer.Deferred()
       stackless.tasklet(self.__echo__)(request, deferred, y)

       return deferred


if __name__== "__main__":
   gw = EchoServer()
   gw.addService(gw.echo, "echo", "echo")

   root = resource.Resource()
   root.putChild('gwplayer', gw)
   reactor.listenTCP(8080, server.Site(root))
   print "server running on localhost:8080"

   task.LoopingCall(stackless.schedule).start(.01)
   stackless.tasklet(reactor.run)()
   stackless.run()