From 8e7a4c0b8bdbefdeb6db9660da97de5320899910 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Wed, 23 Mar 2016 12:49:36 -0400 Subject: initial ideas --- server3.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 server3.py (limited to 'server3.py') diff --git a/server3.py b/server3.py new file mode 100644 index 0000000..8841c14 --- /dev/null +++ b/server3.py @@ -0,0 +1,47 @@ +from klein import run, route + +from twisted.internet.threads import deferToThread +from twisted.protocols import amp +from twisted.internet import reactor + +from ampoule import child, pool + +import sys +from twisted.python import log +log.startLogging(sys.stdout) + +def fib(n): + if n <= 2: + return 1 + else: + return fib(n-1) + fib(n-2) + + +class Fib(amp.Command): + response = [('total', amp.Integer())] + +class DelayedFib(amp.AMP): + def slowFib(self): + result = fib(25) + return result + Fib.responder(slowFib) + +@route('/') +def home(request): + d = pp.doWork(Fib) + return d + + +pp = None + +def start_pool(): + global pp + pp = pool.ProcessPool(child.AMPChild, recycleAfter=5000) + pp.min = 1 + pp.max = 5 + pp.start() + + +if __name__ == "__main__": + reactor.callWhenRunning(start_pool) + run("localhost", 8080) -- cgit v1.2.3