annotate service/reasoning/twisted_sse_demo/api_example.py @ 1106:fe53ca09febc

big rewrites in sse_collector Ignore-this: 3b6278a0cfc57aa686ed39d411fdc35f darcs-hash:d25124b5e0d3c4729ea55530cd3b3064f2af68a7
author drewp <drewp@bigasterisk.com>
date Sun, 28 Aug 2016 18:11:34 -0700
parents cb94ea3495b2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1099
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
1 import time
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
2
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
3 from eventsource import EventSource
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
4
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
5 EVENTSOURCE_URL = 'http://localhost:12000/subscribe'
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
6
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
7 def onmessage(data):
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
8 print 'Got payload with data %s' % data
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
9
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
10 if __name__ == '__main__':
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
11 eventSource = EventSource(EVENTSOURCE_URL)
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
12 eventSource.onmessage(onmessage, callInThread=True)
cb94ea3495b2 Copy from from https://github.com/juggernaut/twisted-sse-demo
drewp <drewp@bigasterisk.com>
parents:
diff changeset
13 time.sleep(20)