Skip to content

Instantly share code, notes, and snippets.

@keis
Created December 21, 2012 06:56
Show Gist options
  • Save keis/4351119 to your computer and use it in GitHub Desktop.
Save keis/4351119 to your computer and use it in GitHub Desktop.

smoke

A concise Publish/Subscribe utility module. It supports both free-form signal names and a stricter style where signals are declared first. You can also mix them.

usage

import smoke

class MyCls(smoke.Broker):
    appears = smoke.signal('appears')
    leaves = smoke.signal('leaves')

def say_hello(what):
    print("hello %s" % (what,))

def say_goodbye(what):
    print("good bye %s" % (what,))

o = MyCls()

# Using broker
o.subscribe("appears", say_hello)
o.publish("appears", what='world')

# Using declared signals
o.leaves.subscribe(say_goodbye)
o.leaves.publish(what='world')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment