annotate lib/twisted_sse/api_example.py @ 510:b1337ad3ec2d

mv twisted_sse Ignore-this: a59fadbe80bc4a393b1dab8228e022c1
author drewp@bigasterisk.com
date Mon, 22 Apr 2019 21:58:09 -0700
parents lib/twisted_sse_demo/api_example.py@7716b1810d6c
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):
510
b1337ad3ec2d mv twisted_sse
drewp@bigasterisk.com
parents: 351
diff changeset
8 print('Got payload with data %s' % data)
294
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)