multithreading - How to use threads in python -


i want use reading values in 17770 files , add of them @ end 1 dictionary object. have machine 8 cores.

this code

def run_item_preprocess ():     scores = {};     in range(1,17771):         filename1 = "x_" + str(i) + ".txt";         lines1 = open(filename1).readlines();         item1 = {};         line in lines1:             tokens = line.split(',');             item1[int(tokens[1])] = int(tokens[2]);         j in range(1,17771):             if j == i:                 continue;             filename2 = "x_" + str(i) + ".txt";             lines2 = open(filename2).readlines();             item2 = {};             line in lines2:                 tokens = line.split(',');                 u = int(tokens[1]);                 r = int(tokens[2]);                 if u in item1:                     item2[u] = r;             if not in scores:                 scores[i] = {};             scores[i]= (s(item1,item2),j); 

here wonderful multiprocessing module. lets parallelise code, using processes not threads. use cores.

an important difference processes don't share memory; queue reduce step.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -