我有一个包含图像列表的文件夹,我从中创建每个图像的哈希,并使用python中的MySQLdb将其逐个插入到sql数据库中。那个文件夹里有大约1400张图片,我需要把它们的哈希值存储在数据库中。但是,每次插入时,它都会消耗掉我的部分空闲RAM,最终得到的是0个空闲RAM空间,并且进程会被终止。我不明白为什么会发生这种情况,因为一次简单的插入不应该导致将整个数据库放入RAM中。因此,在执行插入操作时消耗的RAM量不应取决于数据库的大小。然而,我的公羊已经被时间填满了,尽管我正在这样做self.db.关闭()每次插入后。为什么会发生这种情况,我该怎么解决呢?在
代码如下:
def create_hash(userpath, hashfunc=imagehash.phash):
print "here"
image_filenames = [os.path.join(userpath, path)
for path in os.listdir(userpath) if is_image(path)]
for img in sorted(image_filenames):
try:
hash_img = hashfunc(Image.open(img))
img_url = img.split("/")[-1]
print hash_img
c = Connection()
c.insert(img_url, hash_img)
c.close_connection()
except Exception,e:
print str(e)
下面是Connection类的insert函数:
^{pr2}$请注意,我在上面的代码中使用了this imagehash python library
尝试在一个查询中插入多行。在
看,记忆还在流失。在
相关问题 更多 >
编程相关推荐