Skip to content

Commit 436a3ae

Browse files
committed
Change the long polling example to print multiple messages.
1 parent c9a915f commit 436a3ae

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tutorial.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,13 +934,15 @@ def ajax_endpoint(environ, start_response):
934934
('Content-Type', 'application/json')
935935
]
936936

937-
try:
938-
datum = data_source.get(timeout=5)
939-
except Empty:
940-
datum = []
941-
942937
start_response(status, headers)
943-
return json.dumps(datum)
938+
939+
while True:
940+
try:
941+
datum = data_source.get(timeout=5)
942+
yield json.dumps(datum) + '\n'
943+
except Empty:
944+
pass
945+
944946

945947
gevent.spawn(producer)
946948

0 commit comments

Comments
 (0)