Hello,
I'm trying to emulate a websocket_recv with a timeout, and I wonder if
it is safe to use select. I don't use any asyncio stuff. The example
below seems to work, but are there any side effects I should consider?
Could I also use uwsgi.websocket_recv (i.e. w/o _nb) I this case and
have a guarantee that it will not block?
Thanks,
Bastian
#!/usr/bin/envpython
import logging
import select
import uwsgi
logger = logging.getLogger()
logging.basicConfig(level=logging.NOTSET)
def app(env, sr):
uwsgi.websocket_handshake()
logger.debug('Initialized WebSocket connection.')
websocket_fd = uwsgi.connection_fd()
while True:
readables, _, _ = select.select([websocket_fd], [], [], 3)
if not readables:
# timeout
pass
for fd in readables:
if fd == websocket_fd:
try:
msg = uwsgi.websocket_recv_nb()
except IOError:
# connection was closed
logger.debug('Connection was closed by client')
return []
logger.debug('Got message: {0}'.format(msg))
return []
--
Dr. Bastian Venthur http://venthur.de
Debian Developer venthur at debian org
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi