Django multiprocessing and database connections

前端 未结 9 860
挽巷
挽巷 2020-11-28 03:16

Background:

I\'m working a project which uses Django with a Postgres database. We\'re also using mod_wsgi in case that matters, since some of my web searches have m

9条回答
  •  醉话见心
    2020-11-28 03:51

    When using multiple databases, you should close all connections.

    from django import db
    for connection_name in db.connections.databases:
        db.connections[connection_name].close()
    

    EDIT

    Please use the same as @lechup mentionned to close all connections(not sure since which django version this method was added):

    from django import db
    db.connections.close_all()
    

提交回复
热议问题