import os
import logging
from uwsgidecorators import postfork
from flask import Flask
from model.base import db
from route.base import blueprint

# Register models and routes
import model
import route

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)
# app.config['PROPAGATE_EXCEPTIONS'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://' +\
                                        os.environ['USER'] + ':' +\
                                        os.environ['PASSWORD'] + '@' +\
                                        'db/' + os.environ['SCHEMA']

db.init_app(app)

with app.test_request_context():
    db.create_all()
    db.session.commit()

app.register_blueprint(blueprint)


@postfork
def refresh_db():
    db.session.remove()
    db.init_app(app)

import os
import logging
from flask import Flask
from model.base import db
from route.base import blueprint

# Register models and routes
import model
import route

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)
# app.config['PROPAGATE_EXCEPTIONS'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://' +\
                                        os.environ['USER'] + ':' +\
                                        os.environ['PASSWORD'] + '@' +\
                                        'db/' + os.environ['SCHEMA']

db.init_app(app)

with app.test_request_context():
    db.create_all()
    db.session.commit()

app.register_blueprint(blueprint)

--- 
+++ 
@@ -1,5 +1,6 @@
 import os
 import logging
+from uwsgidecorators import postfork
 from flask import Flask
 from model.base import db
 from route.base import blueprint
@@ -24,3 +25,9 @@
     db.session.commit()
 
 app.register_blueprint(blueprint)
+
+
+@postfork
+def refresh_db():
+    db.session.remove()
+    db.init_app(app)
Refresh db connections on uwsgi fork
