-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Il 09/12/2011 21:18, Massimo Di Stefano ha scritto: > Ciao, > > sto provando ad imparare ad usare la libreria thread … ma ho dei problemi :-( >
I problemi veri non li hai ancora visti :-) Attenzione a limitare l'uso dei thread: ad esempio se devi scaricare 100 files *evita* di eseguire 100 threads; le prestazioni ne potrebbero risentire pesantemente. Io userei un threadpool + map; "peccato" che sia disponibile solo in multiprocessing (che usa i processi e non i thread): http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers > il mio obiettivo e' il download di alcuni file da internet con urlib > salvarli in un file temporaneo > e scrivere in una lista il path di tali file. > > is codice di seguito, e' scarica i file e li salva come file temporanei > … ma non riesco a capire come salvarne una lista dei path. > > ######################################################################################## > # thread test > > import threading > import urllib > from tempfile import NamedTemporaryFile > > class download(threading.Thread): > def __init__(self, sitecode): > threading.Thread.__init__(self) > self.sitecode = sitecode > self.status = -1 > > def run(self): > #global filelist > #filelist = [] > url = > 'http://waterdata.usgs.gov/nwis/monthly?referred_module=sw&site_no=' > url += self.sitecode > url += > '&PARAmeter_cd=00060&partial_periods=on&format=rdb&submitted_form=parameter_selection_list' Esiste un modo migliore per costruire una URL con dei parametri di query: http://docs.python.org/library/urllib.html#urllib.urlencode > tmp = NamedTemporaryFile(delete=False) > urllib.urlretrieve(url, tmp.name) > print 'loaded Monthly data for sitecode : ', self.sitecode > #filelist.append(tmp.name) > #return filelist > Perchè hai commentato filelist.append? > [...] Ciao Manlio -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk7jjPAACgkQscQJ24LbaUTCUACgjaswDAZPoJSVDFFATuu85j3C /5EAn0Rcsl1BpLT76LFkEIhC+bagAUa8 =mcLP -----END PGP SIGNATURE----- _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python