print(fileName) urllib.request.urlretrieve(download_links, fileName) file = drive.CreateFile({'title': fileName}) file.SetContentFile(fileName) file.Upload() song["link"] = 'https://docs.google.com/uc?export=download&id=' + file['id'] print('Inserting: ' + name) songs.insert_one(song) except Exception as e: print("type error: " + str(e)) threads = Threads(3, data) threads.run(func, None) threads.join()
from threads import Threads import time import urllib import threading def handler(data, extra): ex, lock = extra f = urllib.urlopen(data) response = f.read() with lock: with open(ex, "a") as f: f.write(response) lock = threading.Lock() data = ['http://www.google.com/'] * 100 extra = ('./text.txt', lock) threads = Threads(100, data) threads.run(handler, extra) threads.join() # Done