On Thu, Mar 12, 2015 at 12:49 PM, Tim Tisdall <[email protected]> wrote:
>> Can't reproduce it using "normal" sockets, can you paste a minimal WSGI
>> app to reproduce it ? (in this way i can debug it)
>
> I'll see what I can do...  It's hard to find the time.

Okay, didn't take as long as I thought it would...  It's run with
"uwsgi --http :9090 --wsgi-file minimal_async_bug.py --master
--processes 1 --async 100 --ugreen"

-------------------------------
# minimal_async_bug.py
"""
Output:

core99: wait 5 seconds on fd 15
core99: suspended for 0.001549 seconds
core99: break on EAGAIN
core99: wait 5 seconds on fd 15
core99: suspended for 5.005221 seconds
core99: wait 5 seconds on fd 15
"""
import logging
import time

import zmq
import uwsgi


log = logging.getLogger(__name__)

context = zmq.Context()

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])

    zmqsoc = context.socket(zmq.SUB)
    zmqsoc.connect('ipc:///opt/publisher')

    return msg_generator(zmqsoc, env)


def msg_generator(zmqsoc, environ):
    while True:
        timeleft_seconds = 5

        timestamp_before_suspend = time.time()
        log.critical("core%s: wait %d seconds on fd %d",
environ.get('uwsgi.core'), timeleft_seconds, zmqsoc.FD)
        uwsgi.wait_fd_read(zmqsoc.FD, timeleft_seconds)
        uwsgi.suspend()
        log.critical("core%s: suspended for %f seconds",
environ.get('uwsgi.core'), time.time() - timestamp_before_suspend)

        fd = uwsgi.ready_fd()
        if fd > -1:
            result = []
            while True:
                try:
                    result.append(
                        zmqsoc.recv_multipart(flags=zmq.NOBLOCK)
                    )
                except zmq.ZMQError as e:
                    if e.errno == zmq.EAGAIN:
                        log.critical("core%s: break on EAGAIN",
environ.get('uwsgi.core'))
                        break
                    else:
                        raise
            for x in result:
                log.critical("x:%s", str(x))
                yield x
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to