'How to download alots of page by twenty-twenty
I have an app that download a books, where each book can contain a random pages. So I coded a logic using threading:
while pagenum < (int(Book["total_pages"])+1):
tlist = []
for a in range (20):
if pagenum < (int(Book["total_pages"])+1):
x = threading.Thread(target=ThreadDownloads, args=(queue, pagenum, destination))
tlist.append(x)
pagenum += 1
for x in tlist:
x.start()
for x in tlist:
x.join()
The ThreadDownloads
functions is download a specified pages and it's working great, so the problem is this: it ran ThreadDownloads
20 times but it downloaded only a part of the pages:
- pages between 1 and 7 but not those between 8 and 20
- pages between 21 and 29 but not those between 30 and 40
I dont think my ThreadDownloads
function is working correctly because before applying threading it was running fine.
Any help is appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|