import time
import threading
errerLevel = 1
TOTAL_OK = 24
lineList = []
threadLock = threading.Lock()
threads = []
class myThread (threading.Thread):
def __init__(self, index):
threading.Thread.__init__(self)
self.index = index
def run(self):
lineNumber = 0
previous = -2
total = 0
with open(r'D:\kerneldump.bin', 'rb') as f:
line = f.read(16)
while line:
b = [elem for elem in line]
if b[self.index] - previous == errerLevel:
total = total + 1
if TOTAL_OK == total:
threadLock.acquire()
lineList.append((lineNumber - TOTAL_OK) * 16)
threadLock.release()
print(lineNumber - TOTAL_OK)
total = 0
else:
total = 0
previous = b[self.index]
line = f.read(16)
lineNumber = lineNumber + 1
if __name__ == "__main__":
column = 16
begin=time.time()
for i in range(column):
aThread = myThread(i)
aThread.start()
threads.append(aThread)
for i in range(column):
threads[i].join()
print(lineList)
end=time.time()
print("cost time:", end-begin)