打开文件太多python [英] Too many open files python

查看:115
本文介绍了打开文件太多python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调整图片大小。它工作正常,但我的 ImageField ,这是 to_field ,正在打开但未关闭。所以我有一个错误太多的打开文件。我尝试了一些解决方案,但是我无法解决问题。以下是代码:

I'm trying to resize images. It works fine, but my ImageField, which is to_field, is opening but not closing. So I have an error too many open files. I tried some work-around solutions but I wasn't able to fix the problem. Here is the code:

if( to_field.width != size[0] and to_field.height != size[1] ):
   to_field.open()
   image = Image.open(StringIO(to_field.read()))
   old_file_path = to_field.path
   image.resize(size).save(to_field.path)

任何建议?

推荐答案

旧问题,但我认为这是需要关闭的django字段 to_field

Old question but I think it is the django field to_field that needs to be closed:

to_field.close()

这篇关于打开文件太多python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆