[Python] python threads, how to store results from a multithread code
Massimo Di Stefano
massimodisasha a gmail.com
Ven 9 Dic 2011 21:38:18 CET
e quello che sto provando a capire come si fa … :(
Il giorno Dec 9, 2011, alle ore 3:35 PM, Daniele Maccio ha scritto:
> Premetto che non ho avuto il tempo per leggere approfonditamente il
> tuo codice, ma non potresti semplicemente fare lista.append(path)
> dentro il tuo thread, avendo la premura di mettere il codice sotto
> lock?
>
>>
>> ########################################################################################
>> # 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'
>> tmp = NamedTemporaryFile(delete=False)
>> urllib.urlretrieve(url, tmp.name)
>> print 'loaded Monthly data for sitecode : ', self.sitecode
>> #filelist.append(tmp.name)
>> #return filelist
>>
>>
>>
>> sitecodelist = ['01046500', '01018500', '01010500', '01034500', '01059000', '01066000', '01100000']
>>
>> for k in sitecodelist:
>> get_data = download(k)
>> get_data.start()
>>
>> ########################################################################################
>>
Maggiori informazioni sulla lista
Python