Skip to content

Instantly share code, notes, and snippets.

@mangoliou
Created May 10, 2016 02:32
Show Gist options
  • Save mangoliou/bfbd6897bc8ffbb69f1e933f4da415a7 to your computer and use it in GitHub Desktop.
Save mangoliou/bfbd6897bc8ffbb69f1e933f4da415a7 to your computer and use it in GitHub Desktop.
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