1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import random,time,threading
lists = ['python','django','tornado', 'flask','bs5','request','uvloop']
new_lists = []
def work(): if len(lists) == 0: return data = random.choice(lists) lists.remove(data) new_data = '%s_new' % data new_lists.append(new_data) time.sleep(2)
if __name__ == '__main__': start = time.time() t_list = [] for i in range(len(lists)): t = threading.Thread(target=work) t_list.append(t) t.start() for t in t_list: t.join()
print('old list:',lists) print('new list:',new_lists) print('times is %s' %(time.time()-start))
|