推荐学习书目
› 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
loading
V2EX  ›  Python

db.close()

  •  
  •   loading · Apr 2, 2012 · 4522 views
    This topic created in 5288 days ago, the information mentioned may be changed or developed.
    在看peewee文档的例子说明时,文档中有这段:
    Because sqlite likes to have a separate connection per-thread, we will tell flask that during the request/response cycle we need to create a connection to the database. Flask provides some handy decorators to make this a snap:

    @app.before_request
    def before_request():
    g.db = database
    g.db.connect()

    @app.after_request
    def after_request(response):
    g.db.close()
    return response

    是不是只有用sqlite的时候才需要 db.connect(),然后 db.close呢?
    我看其他例子都没见到db.close影子,记得asp+access时随处可见。
    2 replies  •  1970-01-01 08:00:00 +08:00
    kingwkb
        1
    kingwkb  
       Apr 6, 2012 via Android
    这个有没有都行,一个请求执行完毕后会释放所有资源
    loading
        2
    loading  
    OP
       Apr 6, 2012 via Android
    @kingwkb 感谢解惑
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2706 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:00 · PVG 22:00 · LAX 07:00 · JFK 10:00
    ♥ Do have faith in what you're doing.