简体   繁体   English

python打开文件太多

[英]Too many open files python

I'm trying to resize images. 我正在尝试调整图像大小。 It works fine, but my ImageField , which is to_field , is opening but not closing. 它工作正常,但我的ImageField的 ,这是to_field ,正在打开,但不关闭。 So I have an error too many open files . 所以我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)

Any advice?? 有什么建议吗??

老问题,但我认为是django字段to_field需要关闭:

to_field.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM