python futures geeksforgeeks

Solutions on MaxInterview for python futures geeksforgeeks by the best coders in the world

showing results for - "python futures geeksforgeeks"
Tymeo
20 Feb 2020
1import requests
2import concurrent.futures
3
4def get_wiki_page_existence(wiki_page_url, timeout=10):
5    response = requests.get(url=wiki_page_url, timeout=timeout)
6
7    page_status = "unknown"
8    if response.status_code == 200:
9        page_status = "exists"
10    elif response.status_code == 404:
11        page_status = "does not exist"
12
13    return wiki_page_url + " - " + page_status
14
15wiki_page_urls = [
16    "https://en.wikipedia.org/wiki/Ocean",
17    "https://en.wikipedia.org/wiki/Island",
18    "https://en.wikipedia.org/wiki/this_page_does_not_exist",
19    "https://en.wikipedia.org/wiki/Shark",
20]
21with concurrent.futures.ThreadPoolExecutor() as executor:
22    futures = []
23    for url in wiki_page_urls:
24        futures.append(executor.submit(get_wiki_page_existence, wiki_page_url=url))
25    for future in concurrent.futures.as_completed(futures):
26        print(future.result())
similar questions
queries leading to this page
python futures geeksforgeeks