annotate service/reasoning/twisted_sse_demo/api_example.py @ 294:14ac4a210dbc

Copy from from https://github.com/juggernaut/twisted-sse-demo Ignore-this: a252d3c6e023cb83fd10bfbae78e05d9
author drewp@bigasterisk.com
date Fri, 19 Aug 2016 10:53:03 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
294
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
1 import time
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
2
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
3 from eventsource import EventSource
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
4
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
5 EVENTSOURCE_URL = 'http://localhost:12000/subscribe'
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
6
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
7 def onmessage(data):
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
8 print 'Got payload with data %s' % data
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
9
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
10 if __name__ == '__main__':
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
11 eventSource = EventSource(EVENTSOURCE_URL)
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
12 eventSource.onmessage(onmessage, callInThread=True)
14ac4a210dbc Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp@bigasterisk.com
parents:
diff changeset
13 time.sleep(20)