title: Snowflake Authentication Token expired (390114) - Is there a heartbeat code for Snowflake-SQLAlchemy?
body: <p>I have developed a Flask application connecting to Snowflake DB as the backend using SQLAlchemy. I ran into Snowflake authentication token expired issue if the website remains idle for more than 4 hrs. I looked over in Google and found an answer </p>
  
  <p><a href="https://github.com/snowflakedb/gosnowflake/issues/160" rel="nofollow noreferrer">https://github.com/snowflakedb/gosnowflake/issues/160</a></p>
  
  <p>but it doesn't seem valid for Snowflake-SQLAlchemy. </p>
  
  <p>I implemented a heartbeat code using APScheduler which fires "Select 1" every 50 mins but if the session is active in the browser (SSO) it throws "Authentication token has expired" error. </p>
  
  <pre><code>from sqlalchemy import create_engine
  engine = create_engine('snowflake://&lt;connection-string&gt;' )
  connection = engine.connect()
  names = connection.execute_query("select names from employees")
  
  def sensor():
      """ Function for scheduling purposes. """
      v = cursor.execute("""select 1""")
      v = v.fetchall()
      print(v)
  
  sched = BackgroundScheduler(daemon=True)
  sched.add_job(sensor,'interval',minutes=50)
  sched.start()
  </code></pre>