我对python列表有疑问,如何通过在列表上设置缓冲区来向后迭代?我的意思是如果路径不正确,请将其保留在内存中,然后再次迭代? 我的代码示例:
def clientthread(conn):
#Infinite loop so that function do not terminate and thread do not end.
# Array of input data, check for complete transaction from PID
while True:
# Recive true data
data = conn.recv(4069)
newpid = os.fork()
if newpid == 0:
child()
else:
bufsize = 0
input_data = []
input_miss = []
if data:
# Check data
pids = (os.getpid(), newpid)
print "Parent: %d, Child: %d" % pids
# Split line
word = data.split(';')
if word[0] == "START":
channel = word[2]
fileName = word[6].rstrip()
yearMonth = word[3]
channelID = word[1]
videoStart = word[5]
day = word[4]
file_name = path_images+channel+'/'+yearMonth+'/'+day+'/'+fileName+'/'+fileName+'.txt'
create_file = open(file_name,'w+', bufsize)
elif word[0] == "END":
# End loop if come END
break
else:
if pids:
slika = path_images+channel+'/'+yearMonth+'/'+day+'/'+fileName+'/'+fileName+'_'+word[0]+".jpg"
input_data.append(slika)
# Loop for reading images from buffer, and try to make hash on each, if fails stay opened till END come, on succed remove from array
for image in input_data:
if os.path.exists(image):
#print image
hash1 = pHash.imagehash(image)
#print hash1
print >> create_file ,fileName+","+channelID+","+yearMonth+","+word[0]+","+str(hash1)+","+word[1].rstrip()+","+videoStart
input_data.remove(image)
if not os.path.exists(image):
input_miss.append(image)
print image
else:
for miss in input_miss:
if os.path.exists(miss):
hash_miss = pHash.imagehash(miss)
print hash_miss + 'check on'
print >> create_file ,fileName+","+channelID+","+yearMonth+","+word[0]+","+str(hash_miss)+","+word[1].rstrip()+","+videoStart
input_miss.remove(miss)
else:
time.sleep(60)
#came out of loop
conn.close()
我期待价值,并检查每张图片的路径。我的问题是,如果不是真的话,如何在数组中保存变量,并在图像出现时再次开始处理。