Spaces:
Paused
Paused
File size: 1,311 Bytes
1f70049 7859e35 1f70049 5c909a5 1f70049 5c909a5 1f70049 5c909a5 1f70049 7859e35 1f70049 7859e35 1f70049 | 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | from flask import Flask
import grequests
import time
import threading
class Unbuffered(object):
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def writelines(self, datas):
self.stream.writelines(datas)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
import sys
sys.stdout = Unbuffered(sys.stdout)
def myfunc():
num = 1000
url = "https://storage.nts.org.pk/upload/565510/userpic/565510_"
thislist = ["https://storage.nts.org.pk/upload/565510/userpic/565510_1000.jpg"]
while True:
num=num+1
new_url = url+str(num)+".jpg"
thislist.append(new_url)
if(num==10000):
break
print("list completed")
# start_time = time.time()
urls = thislist
rs = (grequests.head(u) for u in urls)
x=1000
for response in grequests.map(rs):
x=x+1
# print(response.status_code, response.elapsed.total_seconds())
if(response.status_code==200):
print("Got it at "+str(x))
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World'
@app.route('/start')
def started():
t1 = threading.Thread(target=myfunc)
t1.start()
return 'Started'
if __name__ == '__main__':
app.run()
|