title: Set database connection timeout in Python
body: <p>I'm creating a RESTful API which needs to access the database.  I'm using Restish, Oracle, and SQLAlchemy.  However, I'll try to frame my question as generically as possible, without taking Restish or other web APIs into account.</p>
  
  <p>I would like to be able to set a timeout for a connection executing a query.  This is to ensure that long running queries are abandoned, and the connection discarded (or recycled).  This query timeout can be a global value, meaning, I don't need to change it per query or connection creation.</p>
  
  <p>Given the following code:</p>
  
  <pre><code>import cx_Oracle
  import sqlalchemy.pool as pool
  
  conn_pool = pool.manage(cx_Oracle)
  conn = conn_pool.connect("username/p4ss@dbname")
  conn.ping()
  
  try:
      cursor = conn.cursor()
      cursor.execute("SELECT * FROM really_slow_query")
      print cursor.fetchone()
  finally:
      cursor.close()
  </code></pre>
  
  <p>How can I modify the above code to set a query timeout on it?
  Will this timeout also apply to connection creation?</p>
  
  <p>This is similar to what java.sql.Statement's setQueryTimeout(int seconds) method does in Java.</p>
  
  <p>Thanks</p>