Thank you for the advice. I was proposing the following:
def clientToRedis(redis):
while True:
msg = uwsgi.websocket_recv()
redis.publish('foobar', msg)
def redisToClient(channel):
while True:
for msg in channel.listen():
uwsgi.websocket_send(msg.get('data'))
I wanted to spawn both functions in two Greenlets but uwsgi won't let me. UWSGI
is only callable form the main callable.
The first listens to the browser and when something comes in it pushes it onto
the redis channel foobar.
The second check the channel for messages and pushes them through the websocket.
Since uwsgi won't allow me to call the uwsgi module form within Greenlets how
do work around this.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of Roberto De Ioris
Sent: 17 May 2013 12:40
To: uWSGI developers and users list
Subject: Re: [uWSGI] Python Decorators
> 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
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi