Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using uWSGI's asyncio engine & Redis for generic websocket communication #34

Open
ggold6 opened this issue Jul 1, 2015 · 0 comments
Open

Comments

@ggold6
Copy link

ggold6 commented Jul 1, 2015

Following issue #27, i've been trying to implement a send/receive asyncio listener coroutine as follows:


websock = WebSocket(app)
@websock.route('/websocket')
def echo(ws):
    r = redis_conn.pubsub()
    r.subscribe("test_channel")
    asyncio.Task(listen(ws,r))

With the coroutine (called as a task, temporary: to edit to something sensible when bugs clear):

@asyncio.coroutine
def listen(ws,r):
    for msg in r.listen():
        ws.send(str(msg['data']))
    
    while True:
        msg=ws.receive()
        if msg is not None:
            print(msg)
        else:
            yield from asyncio.wait(1)

The server (namely, main flask app) should be able to send a message from anywhere using e.g.,redis_conn.publish('test_channel','hello @'+str(time.time()))

Using uwsgi (compiled with asyncio support) v2.0.10 and greenlet v0.4.7.

It seems uwsgi/websockets using uwsgi's asyncio event loop are is not supported in this configuration; asyncio is not in the supported concurrency models list (here

The error i'm getting when trying to connect is (browser to websocket route):

[BUG] current_wsgi_req NOT FOUND !!!
Task exception was never retrieved
future:  exception=SystemError('you can call uwsgi api function only from the main callable',)>
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "./api/__init__.py", line 80, in try_listen
    msg = ws.receive()
  File "./api/apivenv3/lib/python3.4/site-packages/flask_uwsgi_websocket/websocket.py", line 21, in receive
    return self.recv()
  File "./api/apivenv3/lib/python3.4/site-packages/flask_uwsgi_websocket/websocket.py", line 25, in recv
    return uwsgi.websocket_recv()
SystemError: you can call uwsgi api function only from the main callable

Any way around this error from within flask? [BUG] suggests uWSGI can't tell where the request is from (thread/process issue?)

@ggold6 ggold6 changed the title Using uWSGI's asyncio & Redis Using uWSGI's asyncio engine & Redis for generic websocket communication Jul 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant