title: Real time python app that works on a database
body: <p>I am using postgreSQL with python and the SQL database is such that rows are added regularly. At present, the python program does not know if new data has been added (I used psycopg2 to read rows. But it reads till the end of rows and stops). How can I let my python program constantly search if new data has been added? Or can I let postgreSQL trigger python when a new row is added?</p>
  
  <p>This is what I have currently:</p>
  
  <pre><code>def get_data():
      try:
          connect = psycopg2.connect(database="yardqueue", user="postgres", password="abcd", host="localhost", port="5432")
      except:
          print "Could not open database"
      cur = connect.cursor()
      cur.execute("SELECT id,position FROM container")
      rows = cur.fetchall()
      for row in rows:
          print "ID = ", row[0]
          print "Position = ", row[1]
  </code></pre>
  
  <p>As you see, when I run this, it stops once variable 'row' reaches the last row.</p>
  
  <p><strong>EDIT</strong>: Is there a way I can keep my python code running for a specified amount of time? If so, I can make it go through the database until I kill it. </p>