Skip to content

Instantly share code, notes, and snippets.

0xbe609def9447ce09268abf3c305ca2fdc374ac58
0x3df2b419a2974328a92371b236e2c1e49b665016
@avneesh91
avneesh91 / urls.py
Last active January 12, 2020 12:56
url_list = ['https://docs.python.org/3/library/concurrent.futures.html',
'https://technokeeda.com',
'http://home.pipeline.com/~hbaker1/Futures.html']
@avneesh91
avneesh91 / urls.py
Created January 12, 2020 13:01
Url Description
url_list = ['https://docs.python.org/3/library/concurrent.futures.html',
'https://technokeeda.com',
'http://home.pipeline.com/~hbaker1/Futures.html']
@avneesh91
avneesh91 / without_futures.py
Created January 12, 2020 13:03
Requests without futures
import requests
# need to get all the urls
url_list = ['https://docs.python.org/3/library/concurrent.futures.html',
'https://technokeeda.com',
'http://home.pipeline.com/~hbaker1/Futures.html']
for url in url_list:
response = requests.get(url)
print(response, response.status_code)
@avneesh91
avneesh91 / with_futures.py
Created January 12, 2020 13:04
With_futures
import requests
from concurrent.futures import ThreadPoolExecutor
url_list = ['https://docs.python.org/3/library/concurrent.futures.html', \
'https://technokeeda.com', \
'http://home.pipeline.com/~hbaker1/Futures.html']
def get_futures_get(urls):
results = []
currs = ThreadPoolExecutor(max_workers=5)
for url in urls:
@avneesh91
avneesh91 / with_futures_shutdown.py
Created January 12, 2020 13:05
with_futures_shutdown
currs.shutdown(wait=True)
@avneesh91
avneesh91 / ThreadPoolInitiator.py
Created January 12, 2020 13:06
ThreadPool Initiator
currs = ThreadPoolExecutor(max_workers=5)
@avneesh91
avneesh91 / Response_iterator.py
Created January 12, 2020 13:08
response iterator
for url in urls:
curr_future_result = currs.submit(worker_func, url, results)
@avneesh91
avneesh91 / shut_down.py
Created January 12, 2020 13:09
shut down
currs.shutdown(wait=True)