Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef6b1a5

Browse files
committed
added GeventWebsocketClient::receive_nb() non-blocking receive method
added some documentation to receive() and receive_nb()
1 parent 1a5e4af commit ef6b1a5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

flask_uwsgi_websocket/_gevent.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from gevent import killall, sleep, spawn, wait
44
from gevent.event import Event
5-
from gevent.queue import Queue
5+
from gevent.queue import Queue, Empty
66
from gevent.select import select
77
from gevent.monkey import patch_all; patch_all()
88
import uuid
@@ -29,8 +29,21 @@ def send(self, message):
2929
self.send_event.set()
3030

3131
def receive(self):
32+
""" Receives a message from the websocket (blocking).
33+
:return the message
34+
"""
3235
return self.recv_queue.get()
3336

37+
def receive_nb(self):
38+
""" Receives a message from the websocket (non-blocking).
39+
:return the message or None if no message was available
40+
immediately
41+
"""
42+
try:
43+
return self.recv_queue.get_nowait()
44+
except Empty:
45+
return None
46+
3447
def close(self):
3548
self.connected = False
3649

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='Flask-uWSGI-WebSocket',
6-
version='0.2.5.1',
6+
version='0.2.5.2',
77
url='https://github.com/zeekay/flask-uwsgi-websocket',
88
license='MIT',
99
author='Zach Kelling',

0 commit comments

Comments
 (0)