Skip to content
Discussion options

You must be logged in to vote

Yes, this is not the best way to do what you need. Unfortunately the correct way is much harder.

What you want to do in your subscribe event handler is to start a background task to monitor redis, and then return immediately.

    def on_subscribe(self, payload):
        socketio.start_background_task(watch_redis, request.sid)

Then you can have an independent redis watcher task:

def watch_redis(sid):
    redisClient = r.pubsub()
    while True:
        socketio.sleep(0)
        message = redisClient.get_message(timeout)

        if message:
            socketio.emit("subscribe_response_event", message, to=sid)
            #Emit to client

Then there is the part about stopping this backgroun…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@tmb-ltsdw
Comment options

@tmb-ltsdw
Comment options

@miguelgrinberg
Comment options

@tmb-ltsdw
Comment options

Answer selected by tmb-ltsdw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants