我用下面的代碼作爲多線程來下載圖片,但是我發現速度不是很快,我不知道爲什麼,有沒有人爲我做expalin?即使使用多線程,爲什麼不快?
普通下載:
for imageSecond in imageSeconds:
urlServer = imageSecond.get("src")
pathLocal = formatPath(downloadLocationPath, ntpath.basename(urlServer))
downloadImage(browser, urlServer, pathLocal)
def downloadImage(browser, urlServer, pathLocal):
線程下載:
ts = []
for imageSecond in imageSeconds:
urlServer = imageSecond.get("src")
pathLocal = formatPath(downloadLocationPath, ntpath.basename(urlServer))
ts.append(createNewDownloadThread(browser, urlServer, pathLocal))
for t in ts:
t.join()
def createNewDownloadThread(browser, urlServer, pathLocal):
download_thread = threading.Thread(target=downloadImage, args=(browser, urlServer, pathLocal))
download_thread.start()
return download_thread#.join()
def downloadImage(browser, urlServer, pathLocal):
最有可能的原因是:瓶頸是您的網絡連接,把更多的CPU內核,以simultaneosly使用它無助於改善這一點。 – guidot