Closed dzpt closed 4 months ago
It's working fine for me.
from peewee import *
from playhouse.pool import *
app = Flask(__name__)
db = PooledSqliteDatabase('/tmp/test.db')
@app.before_request
def connect_db():
db.connect()
@app.teardown_request
def close_db(exc=None):
db.close()
import logging
log = logging.getLogger('peewee.pool')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)
@app.route("/")
def hello_world():
return "Hello, World!"
if __name__ == "__main__":
import bjoern
bjoern.run(app, "127.0.0.1", 8000)
Output:
No connection available in pool.
Created new connection 140657885258224.
Returning 140657885258224 to pool.
Returning 140657885258224 to pool.
Returning 140657885258224 to pool.
Returning 140657885258224 to pool.
I'm using bjoern to serve Flask app <-> peewee
I set the stale_timeout is 4 seconds. I close connection in both
app.teardown_appcontext
andapp.teardown_request
.But the connection won't be recycled. Still got the message
playhouse.pool.MaxConnectionsExceeded
even leaving idle for 15 minutes straight.Did i miss something and what should i do to recycle the connection?