-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_downlaoding.py
More file actions
44 lines (34 loc) · 859 Bytes
/
image_downlaoding.py
File metadata and controls
44 lines (34 loc) · 859 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
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python3
import urllib.request as ur
import threading
import queue
import time
lock=threading.Lock()
pic_count=0
def downloader(q):
global pic_count
with lock:
while not q.empty():
try:
ur.urlretrieve(q.get(block=False),"images{}image{}".format("/",pic_count))
print("image{} downloaded".format(pic_count))
except :
print("image{} not downloaded".format(pic_count))
q.task_done()
pic_count+=1
q=queue.Queue()
with open("image_list.txt",'r') as f:
for i in f.readlines():
q.put(i[:-1])
start=time.time()
Thread_list=[]
for i in range(20):
t=threading.Thread(target=downloader,args=[q])
Thread_list.append(t)
t.start()
q.join()
for i in Thread_list:
i.join()
print(i.name," has joined")
end=time.time()
print(end-start)