1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
from streamz import Stream
import asyncio
from tornado.platform.asyncio import AsyncIOMainLoop
AsyncIOMainLoop().install()
source = Stream()
s = source.sliding_window(2).map(sum)
L = s.sink_to_list() # store result in a list
s.rate_limit(0.5).sink(source.emit) # pipe output back to input
s.rate_limit(1.0).sink(lambda x: print(L)) # print state of L every second
source.emit(0) # seed with initial values
source.emit(1)
def run_asyncio_loop():
loop = asyncio.get_event_loop()
try:
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.close()
run_asyncio_loop()
|