Created
November 28, 2012 22:16
Revisions
-
bamthomas revised this gist
Nov 28, 2012 . 1 changed file with 3 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,12 +13,8 @@ def sub(myredis, name): for item in pubsub.listen(): print '%s : %s' % (name, item['data']) if __name__ == '__main__': myredis = redis.Redis() Process(target=pub, args=(myredis,)).start() Process(target=sub, args=(myredis,'reader1')).start() Process(target=sub, args=(myredis,'reader2')).start() -
bamthomas created this gist
Nov 28, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ from multiprocessing.process import Process import time import redis def pub(myredis): for n in range(10): myredis.publish('channel','blah %d' % n) time.sleep(5) def sub(myredis, name): pubsub = myredis.pubsub() pubsub.subscribe(['channel']) for item in pubsub.listen(): print '%s : %s' % (name, item['data']) if __name__ == '__main__': myredis = redis.Redis() write_p = Process(target=pub, args=(myredis,)) write_p.start() read_p = Process(target=sub, args=(myredis,'reader1')) read_p.start() read_p2 = Process(target=sub, args=(myredis,'reader2')) read_p2.start()