File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 66 from crawler import crawl_image_urls
77except ImportError : # Python 3
88 from .crawler import crawl_image_urls
9- from typing import Counter , List
9+ from typing import List
1010from multiprocessing .pool import ThreadPool
1111from time import time as timer
1212import os
1313import math
1414
15+ _FINISH = False
16+
1517
1618def fetch_image_urls (
1719 query : str ,
@@ -86,11 +88,16 @@ def rename_images(dir, prefix):
8688
8789
8890def download_image_entries (entries , pool_size , limit ):
91+ global _FINISH
8992 counter = 1
90- results = ThreadPool (pool_size ).imap_unordered (
93+ _FINISH = False
94+ pool = ThreadPool (pool_size )
95+ results = pool .imap_unordered (
9196 download_image_with_thread , entries )
9297 for (url , result ) in results :
9398 if counter > limit :
99+ _FINISH = True
100+ pool .terminate ()
94101 break
95102 if result :
96103 print ("#{} {} Downloaded" .format (counter , url ))
@@ -109,6 +116,8 @@ def get_image_entries(urls, dir):
109116
110117
111118def download_image_with_thread (entry ):
119+ if _FINISH :
120+ return
112121 url , path = entry
113122 result = download_image (url , path )
114123 return (url , result )
Original file line number Diff line number Diff line change 11[metadata]
22name = bing_images
3- version = 0.1.0
3+ version = 0.1.1
44author = CatchZeng
55author_email = catchzenghh@gmail.com
66description = Python library to fetch image urls and download using multithreading from Bing.com.
You can’t perform that action at this time.
0 commit comments