-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession22.py
More file actions
33 lines (23 loc) · 787 Bytes
/
session22.py
File metadata and controls
33 lines (23 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Multi-threading/ Concurrent Programming/ Parallel Programming
import requests
import threading
url1 = "https://newsapi.org/v2/everything?q=apple&from=2019-07-02&to=2019-07-02&sortBy=popularity&apiKey=29f3bc59341f454b865eafa4af29cd10"
url2 = "http://www.json-generator.com/api/json/get/chQLxhBjaW?indent=2"
print("App started..")
class FetchNews(threading.Thread):
def run(self):
print("Fetching news from url1")
response1 = requests.get(url1)
print(response1.text)
class FetchBook(threading.Thread):
def run(self):
print("Fetching news from url1")
response2 = requests.get(url2)
print(response2.text)
a = FetchNews()
b = FetchBook()
a.start()
b.start()
for i in range(1, 11):
print("i is:",i)
print("App finished")