Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Check For Websocket Data #84

Closed
limitedAtonement opened this issue Sep 30, 2024 · 2 comments
Closed

Check For Websocket Data #84

limitedAtonement opened this issue Sep 30, 2024 · 2 comments
Labels
question Further information is requested

Comments

@limitedAtonement
Copy link

limitedAtonement commented Sep 30, 2024

The handler in examples/clock.py looks like this:

@sock.route('/clock')
def clock(ws):
    client_list.append(ws)
    while True:
        data = ws.receive()
        if data == 'stop':
            break
    client_list.remove(ws)

When terminating the server, the termination is held up because of the blocking call on ws.receive(). It would be better if we could do something like

@sock.route('/clock')
def clock(ws):
    client_list.append(ws)
    while keep_running():
        if ws.available():
            data = ws.receive()
            if data == 'stop':
                break
        else:
            time.sleep(.5)
    client_list.remove(ws)

keep_running can be set up to return False if a SIG_TERM was sent or whatever.

Is there any way to get this type of non-blocking behavior?

@miguelgrinberg
Copy link
Owner

What happens when SIGTERM is received varies depending on the web server that you are using. A proper handling of SIGTERM by the web server would close all open handles, which would in turn raise an exception on the receive() call. Not sure what web server you are using, but I would prefer to not add code in this package to compensate for web servers that don't do this correctly.

@miguelgrinberg miguelgrinberg added the question Further information is requested label Oct 1, 2024
@limitedAtonement
Copy link
Author

A just response. I'm using gunicorn (without gevent and eventlet at the moment). I'll see what it takes to get gunicorn to close IO handles on SIGTERM.

Repository owner locked and limited conversation to collaborators Oct 31, 2024
@miguelgrinberg miguelgrinberg converted this issue into discussion #97 Oct 31, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants