swapping out Gunicorn for fapws3 in a heavily gevented app

183 views
Skip to first unread message

Adam Hitchcock

unread,
Jul 16, 2012, 11:58:11 AM7/16/12
to fa...@googlegroups.com
Is this possible?

I'm currently using gevent + gunicorn and I have greenlets everywhere. In some toy examples fapws is not behaving in a cooperative manner with gevent.

One example is that sleep statements don't seem to be yielding the thread in the way I would expect with gevent. Here is a simple example where I yield data via a generator. If you have multiple curls going on at once the sleeps seem to stack across requests.

Thoughts?

-adam


#!/usr/bin/env python
from gevent import monkey
monkey.patch_all()

from gevent.queue import Queue
from gevent import sleep
from gevent import spawn

import fapws._evwsgi as evwsgi
from fapws import base


class Generator(object):
    def __init__(self):
        super(Generator, self).__init__()
        self.gens = []
        spawn(self.forever)

    def forever(self):
        while True:
            for gen, pipe in self.gens:
                pipe.put(gen.next())
            sleep(0)

    def add(self, i=0):
        def _serial(i=0):
            while True:
                yield str(i)
                i += 1
                sleep(i)
        pipe = Queue()
        self.gens.append((_serial(), pipe))
        return pipe

G = Generator()


def start():
    evwsgi.start('0.0.0.0', '8080')
    evwsgi.set_base_module(base)

    def serial(environ, start_response):
        start_response('200 OK', [('Content-Type', 'application/json')])
        gen = G.add()
        return gen

    evwsgi.wsgi_cb(('/serial', serial))

    evwsgi.set_debug(0)
    evwsgi.run()

if __name__ == '__main__':
    start()

Reply all
Reply to author
Forward
0 new messages