Created
June 30, 2010 20:10
-
-
Save ntamas/459154 to your computer and use it in GitHub Desktop.
This file contains 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 characters
""" | |
``vuvuzela.py`` adds the glorious sound of the vuvuzela to any | |
Python program. | |
Based on the excellent idea of Chris Williams. See also: | |
<http://search.cpan.org/~bingos/Acme-Vuvuzela-0.02> | |
Usage:: | |
>>> import vuvuzela | |
""" | |
import os, random, sys, time | |
__author__ = "Tamas Nepusz" | |
__license__ = "MIT" | |
class Vuvuzela(object): | |
def __init__(self): | |
self.PID = None | |
def start(self): | |
if self.PID: | |
return | |
self.PID = os.fork() | |
if not self.PID: | |
sys.stdout.write("B") | |
sys.stdout.flush() | |
while True: | |
sys.stdout.write(random.choice("Zzzz")) | |
sys.stdout.flush() | |
time.sleep(0.2) | |
def stop(self): | |
if self.PID: | |
os.kill(self.PID) | |
self.PID = None | |
Vuvuzela().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment