Last active
August 23, 2022 11:53
-
-
Save shikendon/e47dcc03cb8f31048049c55bad533b61 to your computer and use it in GitHub Desktop.
Used in RubyConf Taiwan 2016 https://www.slideshare.net/shikendon/crawler-from-zero
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
#!/usr/bin/env python3 | |
import threading | |
import urllib.request | |
def worker(index, results): | |
req = urllib.request.urlopen('https://www.facebook.com/') | |
results.append(req.getcode()) | |
results = [] | |
threads = [] | |
for i in range(1000): | |
t = threading.Thread(target=worker, args=(i, results)) | |
threads.append(t) | |
t.start() | |
for t in threads: | |
t.join() | |
print(set(results)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment