Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribing twice on the same channel prevents further new subscriptions #24

Open
lucap opened this issue Mar 21, 2012 · 0 comments
Open

Comments

@lucap
Copy link

lucap commented Mar 21, 2012

The example code below should expose the issue. Subscribing twice on the same channel, prevents further new subscriptions on any channel.

Calling listen() only once doesn't seem to help.

import time
import random
from functools import partial

import brukva
import tornado


def start_data_producer():

    now = time.time()
    ioloop = tornado.ioloop.IOLoop.instance()

    c = brukva.Client()
    c.connect()

    def pub(channel):
        data = random.randint(0,10)
        print "Publishing %s on %s" % (data, channel)
        c.publish(channel, data)

    tick = tornado.ioloop.PeriodicCallback(partial(pub, "test"), 1000)
    tick.start()

    tick2 = tornado.ioloop.PeriodicCallback(partial(pub, "test_2"), 1000)
    tick2.start()

def run_test():

    now = time.time()
    ioloop = tornado.ioloop.IOLoop.instance()

    c = brukva.Client()
    c.connect()

    def callback(result):
        print "Received: %s" % result.body 

    def unsub(channel):
        print "=== Unsubscribing: %s ===" % channel
        c.unsubscribe(channel)

    def sub(channel):
        print "=== Suscribing: %s ===" % channel
        c.subscribe(channel)
        # Should listen() be called for every subscribe() call?
        c.listen(callback)    

    ioloop.add_timeout(now, partial(sub, "test")) 

    # If we don't perform this second subscribe call then all is good. 
    ioloop.add_timeout(now + 5, partial(sub, "test")) 

    ioloop.add_timeout(now + 10, partial(unsub, "test"))
    ioloop.add_timeout(now + 15, partial(sub, "test"))
    ioloop.add_timeout(now + 20, partial(sub, "test_2"))


if __name__ == '__main__':
    start_data_producer()    
    run_test()
    tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant