Skip to content

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

Open

Description

@lucap

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions