推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
wikinee
V2EX  ›  Python

PIL 包的 Image 方法的 close

  •  
  •   wikinee · Nov 16, 2015 · 6090 views
    This topic created in 3972 days ago, the information mentioned may be changed or developed.
    #url1
    from PIL import Image
    img=Image.open(full_file_path)
    img.save('xxx')


    #url2
    直接利用生成的图片发送到远程服务器
    失败了

    我想结束进程,可是没有 close 方法啊,
    现在网上的教程是:
    f = open ( xxx ,‘ rb ’)
    Image.open(f)
    f.close()
    但是这个没效果,得再请求一次 url2 才行,郁闷
    4 replies  •  2015-11-17 08:56:27 +08:00
    dtysky
        1
    dtysky  
       Nov 16, 2015 via Android
    用 io 库,虚拟一个文件, save 进去,再直接发出去。。。不知道可以满足你的需求不

    import io
    f = io.FileIO
    im.save(f)
    ......
    dtysky
        2
    dtysky  
       Nov 16, 2015 via Android   ❤️ 1
    顺便 PIL 是没有 close 方法的,似乎是创建对象后自动释放文件
    DEMONHUNTER
        3
    DEMONHUNTER  
       Nov 16, 2015   ❤️ 1
    from PIL import Image
    img=Image.open(full_file_path)
    img.save('xxx')

    担心 img 没释放,那就 del 它吧:
    del img
    wikinee
        4
    wikinee  
    OP
       Nov 17, 2015
    @dtysky 确实是自动释放,但是还需要时间,我遇到的是生成之后立马发送会出问题。
    @DEMONHUNTER 我看看,还有这方法。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2438 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 02:55 · PVG 10:55 · LAX 19:55 · JFK 22:55
    ♥ Do have faith in what you're doing.