Created
May 10, 2016 02:32
-
-
Save mangoliou/bfbd6897bc8ffbb69f1e933f4da415a7 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
import threading | |
import urllib2 | |
import time | |
def worker(num): | |
"""thread worker function""" | |
response = urllib2.urlopen('http://python.org/') | |
print 'Worker: %s' % num | |
return | |
# Start time. | |
start_time = time.time() | |
# Create threads | |
threads = [] | |
for i in range(20): | |
t = threading.Thread(target=worker, args=(i,)) | |
threads.append(t) | |
t.start() | |
# Wait all the threads to finish. | |
for t in threads: | |
t.join() | |
# Print the elapsed time. | |
elapsed_time = time.time() - start_time | |
print(elapsed_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment