title: python 2.7 script running two while loops in parallel indefinitely
body: <p>I am trying to execute some code on a Beaglebone Black running ubuntu.  The script has two primary functions:
  1: count digital pulse
  2: store the counted pulses in mySQL every 10s or so</p>
  
  <p>These two functions need to run idefinitely.</p>
  
  <p>My question is how to do get these two functions to run in parallel?  Here is my latest code revision that doesn't work so you can see what I am attempting to do.  Any help much appreciated -- as I new to python.  </p>
  
  <p>Thank you in advance!</p>
  
  <pre><code>#!/usr/bin/python
  
  import Adafruit_BBIO.GPIO as GPIO
  import MySQLdb
  import time
  import thread
  from threading import Thread
  
  
  now = time.strftime('%Y-%m-%d %H:%M:%S')
  total1 = 0
  total2 = 0
  
  
  def insertDB_10sec(now, total1, total2):
      while True:
          conn = MySQLdb.connect(host ="localhost", 
              user="root", 
              passwd="password", 
              db="dbname")
          cursor= conn.cursor()
          cursor.execute("INSERT INTO tablename VALUES (%s, %s, %s)",  (now, total1, total2))
          conn.commit()
          conn.close()
          print "DB Entry Made"
          time.sleep(10)
  
  def countPulse():
      now = time.strftime('%Y-%m-%d %H:%M:%S')
      GPIO.setup("P8_12", GPIO.IN)
      total1 = 0
     total2 = 0
     while True:
      GPIO.wait_for_edge("P8_12", GPIO.RISING)
      GPIO.wait_for_edge("P8_12", GPIO.FALLING)
      now = time.strftime('%Y-%m-%d %H:%M:%S')
      print now
      total1 +=1
      print total1
      return now, total1, total2 
  
  t1 = Thread(target = countPulse)
  t2 = Thread(target = insertDB_10sec(now, total1, total2))
  
  t1.start()
  t2.start()
  </code></pre>