Skip to content

Instantly share code, notes, and snippets.

@cablehead
Created October 24, 2013 21:17
Show Gist options
  • Select an option

  • Save cablehead/7145166 to your computer and use it in GitHub Desktop.

Select an option

Save cablehead/7145166 to your computer and use it in GitHub Desktop.
import sys
import signal
from vanilla import malt
h = malt.Hub()
ch = h.channel()
def beat(name, step, offset=0):
h.sleep(offset)
while True:
try:
ch.put(name)
except malt.Closed:
return
h.sleep(step)
bpm = 120
step = (60*1000)/bpm
offset = step/2
h.spawn(beat, "boom", step)
h.spawn(beat, "tick", step, offset)
@h.spawn
def output():
for name in ch:
sys.stdout.write(name + " ")
sys.stdout.flush()
shutdown = h.signals(signal.SIGINT, signal.SIGTERM)
shutdown.get()
ch.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment