Created
August 19, 2011 00:09
-
-
Save yosemitebandit/1155663 to your computer and use it in GitHub Desktop.
small threading example
This file contains hidden or 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
# 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