this is my code :
import re,threading class key_value: def __init__(self,filename='a.txt'): self.filename = filename def __getitem__(self,key): file = open(self.filename,'r') data = file.read() value = re.findall(r''+str(key)+' - (\S+)',data) return value def __setitem__(self,key,value): data = open(self.filename).read() b = re.split(r'('+str(key)+' - )\S*', data) # if len(b) == 1: result = str(key)+' - '+str(value) result += '\n' file = open(self.filename,'a') file.write(result) return elif type(value) == type([]): result = "".join(str(x) + value.pop(0) if x == str(key)+' - ' else x for x in b) else : result = "".join(str(x) + str(value) if str(x) == str(key)+' - ' else x for x in b) file = open(self.filename,'w') file.write(result) def run(self): print 'the thread is running!!' class do_thread(threading.Thread): def __init__(self,filename='a.txt',key=None,value=None): threading.Thread.__init__(self) self.filename = filename self.key=key self.value=value def run(self): print 'the thread is running!!' a = key_value(self.filename) if(self.key and self.value): a[self.key] = self.value elif(self.key): self.value = a[self.key] #'''#Multi-threading code for i in range(1000): a = do_thread(key=i,value=i) #print 'the main programme' a.start() #a.join() #print 'game over' '''# Single-threaded code for i in range(1000): a = key_value() a[i] = i ''' my boss told me to add Multi-threading to my code ,
i add it , but i find the Multi-threading spend more time ,
so what is the useful of the Multi-threading that my boss said ,
thanks