> On Wednesday, October 17, 2012 7:42:05 PM UTC+1, Roberto De Ioris wrote:
>>
>>
>> Be sure to not have post-buffering option in your uWSGI config.
>> Buffering
>> request body to disk is not async in uWSGI.
>
>
> I do not have post-buffering in my config. Is this buffering for requests
> or responses?
>
> I've managed to work around the cooperative read problem, by patching
> Django's read() from wsgi.input and calling
> gevent.socket.wait_read(environ['wsgi.input'].fileno()) before the actual
> read() call. This way, when there is no data to read, the flow will be
> switched to another greenlet. It seems to work, but I don't know if this
> is
> the correct approach.
Yes, this is the correct approach, gevent monkey_patching cannot patch c
functions/modules.
>
> But I've still got the cooperative write problem. Since my
> application returns an iterator to uWSGI, it seems that it's uWSGI that's
> writing to the client socket, blocking, and not cooperating. Is there an
> wsgi.output environment variable that I can use to wait on, until I'm able
> to write? Or maybe I can reuse wsgi.input, is it the same socket?
>
> On another note, can't uWSGI's gevent loop engine handle these scenarios
> and switch greenlets when a read() does not have anything to read and a
> write() would block?
this is the job of your app, and from a WSGI point of view, what you are
trying to do is a violation of the standard. But honestly, i do not care
it :) You can use the file descriptor exported by uwsgi.connection_fd()
and simply stream data to it.