3

I'm currently running an flask python application running on an NGINX server with the help of uWGI. The static pages are always reachable but the pages that use a connection (MySQL) time out after 2 minutes. What's going on? They become simply become unavailable.

Things I have tried:

  • Not using a global
  • working with pools
  • turning off firewall

.

# using python version 2.7.10 from flask import Flask, jsonify, request, session import mysql.connector.pooling #Make a connection with the DB dbconfig = { "host" : "12.34.5.78", "database": "db", "user": "user", "password": "pass" } conn = mysql.connector.connect(pool_name = "mypool", pool_size = 6, **dbconfig) #Define the root app = Flask(__name__) #Landings page @app.route('/') def index(): return "Hello World." # return all resources by name @app.route('/resources', methods=['GET']) def allResourceNames(): conn1 = mysql.connector.connect(pool_name="mypool") reader = conn1.cursor() query = ("SELECT name FROM resources") reader.execute(query) resources = [] for name in reader: resources.append({'name' : name[0]}) reader.close() conn1.close() return jsonify({"resources" : resources}) if __name__ == "__main__": app.run(debug=True) 

1 Answer 1

3

According to MySQL Python Connector Doc you may want to set connection_timeout as connect option. E.g.,

conn = mysql.connector.connect(pool_name = "mypool", pool_size = 6, connection_timeout=3600, **dbconfig) 
Sign up to request clarification or add additional context in comments.

2 Comments

Could you please post the error msg you're getting in your post? thanks
It worked by the way. But i'm not sure why. I simply changed the connection_timeout=1 and now it's actually quite a bit faster. Could you explain what's actually happening?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.