Skip to content

Instantly share code, notes, and snippets.

@yosemitebandit
Created August 19, 2011 00:09
Show Gist options
  • Save yosemitebandit/1155663 to your computer and use it in GitHub Desktop.
Save yosemitebandit/1155663 to your computer and use it in GitHub Desktop.
small threading example
# http://www.neotitans.com/resources/python/python-threads-multithreading-tutorial.html
import sys
import time
import random
import threading
def worker(name):
print 'I am %s and starting now' % name
wait = random.randint(2,7)
time.sleep(wait)
print 'I am %s and waited %d seconds' % (name, wait)
sys.stdout.flush()
t1 = threading.Thread(target=worker, args=('thread 1',))
t2 = threading.Thread(target=worker, args=('thread 2',))
t3 = threading.Thread(target=worker, args=('thread 3',))
t1.start()
t2.start()
t3.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment