> So this means the websocket runs in its own Greenlet and I ask it if it
> has produced result and if not I check redis for messages.
>

more or less, tha main greenlet (the one spawned by uWSGI) is attached to
the websocket and wait for it. Instead of calling uwsgi.websocket_recv()
(that will wait for a message), you have to wait (in gevent) for
uwsgi.connection_fd() that is the websocket file descriptor.

In the mean time another greenlet (spawned by you) wait for redis.

On no-traffic, both the greenlet are stopped, as soon as one of the two
socket (redis or websocket) is ready the correspondign greenlet will be
woke up.

This approach requires an additional queue to pass infos from the redis
greenlet to the websocket one, so i am not a big fan of it.

The best approach (for me) is waiting in the same greenlet both for redis
and the websocket. If you can report the redis part of your code i will
show you how to integrate it with websockets. In pseudo-code is something
like that:

fd_websocket = uwsgi.connection_fd()
fd_redis = redis_socket

while True:
    fd = wait_for([fd_websocket, fd_redis])
    if fd == fd_websocket:
        msg = uwsgi.websocket_recv()
        redis_send(msg)
    elif fd = fd_redis:
        msg = redis_read
        uwsgi.websocket_send(msg)


-- 
Roberto De Ioris
http://unbit.it
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to