Skip to content

Instantly share code, notes, and snippets.

@sontek
Created May 29, 2013 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sontek/5668052 to your computer and use it in GitHub Desktop.
Save sontek/5668052 to your computer and use it in GitHub Desktop.
Making requests without threadpool
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