Created
May 29, 2013 04:56
-
-
Save sontek/5668052 to your computer and use it in GitHub Desktop.
Making requests without threadpool
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 requests | |
import logging | |
logging.basicConfig() | |
logging.getLogger().setLevel(logging.DEBUG) | |
requests_log = logging.getLogger("requests.packages.urllib3") | |
requests_log.setLevel(logging.DEBUG) | |
http = requests.Session() | |
def fetch(): | |
current_thread = threading.current_thread() | |
print("IN THREAD %s" % current_thread.name) | |
result = http.get('http://sontek.net') | |
result = http.get('http://sontek.net') | |
result = http.get('http://sontek.net') | |
print("Found status %s, content_length %s" % ( | |
result.status_code | |
, len(result.content) | |
) | |
) | |
threads = [] | |
for i in range(0, 10): | |
t = threading.Thread(target=fetch, name="thread%s" % i) | |
t.start() | |
threads.append(t) | |
print("Waiting....") | |
for t in threads: | |
t.join() | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment