def main(args): import pymongo from mongotools.pubsub import Channel cli = pymongo.MongoClient() chan = Channel(cli.test, 'mychannel') chan.ensure_channel() chan.sub(args['-t'], Benchmark(float(args['-s'])).handle) print 'Begin sub benchmark' while True: chan.handle_ready(raise_errors=True, await=True) time.sleep(0.1)
# Subscriber import time import pymongo from mongotools.pubsub import Channel cli = pymongo.MongoClient() chan = Channel(cli.test, 'mychannel') chan.ensure_channel() def printer(chan, msg): print chan, msg chan.sub('foo', printer) chan.sub('bar', printer) while True: chan.handle_ready(await=True) time.sleep(0.1)