title: Python threading - Is this what I need?
body: <p>I'm writing a python script to control various hardware parts of a setup.
  I have a state that I want to keep while other parts of the script do their thing.
  I think this while loop is stopping other parts of the script from running. 
  Do I need to introduce threading so that that loop can continue to run until  I tell it to stop?</p>
  
  <p>Not sure if I am looking at the right method to solve my issue.</p>
  
  <p>edit: 
  I have pasted some of  my code the whole thing is quite large.</p>
  
  <p>This listens to a USB MIDI device for messages of specific types and performs actions based on input values which are listed in inst</p>
  
  <pre><code>while True:
      b = f.read(1)
      s='rawdataB:'+  hex(ord(b))
      print s
  
      if b == '\x90':
          note=True
      elif note:
          if b in inst:
              print "IsNote:"  + str( int(hex(ord(b)), 16))
              noteaction(inst.get(b))
          note=False
  
      if b== '\xB0':
          controller=True
  
      elif controller:
      #grab the controller with byte 1, value with byte 2
          bcount = bcount +1
          cn=hex(ord(b))  #hex value of byte
          if bcount == 1:
              cntrl=cn
              if cntrl== '0xd':
                  fspeedC= 1
                  print 'fspeed cnum'     
  
              elif bcount == 2:
                  cval=cn 
          if fspeedC == 1:
              fspeed= int(cval,16)
              print 'fspeed=' + str(fspeed)
              MotorControl('fwd',fspeed,0)
              print 'moving forward'
              print "cn:" + str(cntrl) + ", val:" + str(cval)
              print "bcount: " + str(bcount)
              bcount=0
              cvalue=True
  
      elif cvalue:
          val=int(hex(ord(b)), 16)
          #print "2val:" + str(val)        
          if val != -1 :
              print "do something" 
              cvalue=False
              print "cn:" + str(cntrl) + ", val:" + str(val)
          controller=False
  
  # this will be a function i guess but also can be in an infinite loop mode when I want it to be
  # however while this is running I still want the above code to monitor the incoming MIDI bytes
  x=0
  while True:
      GPIO.wait_for_edge(11, GPIO.FALLING)  
      #prevent bounce
      time.sleep(0.2)
      x=x+1
      print x
      if x % 2 == 0:
           ControlAPairOfPins("17","1","24","0")
           print "Forward"
      else:
           ControlAPairOfPins("17","0","24","1")
           print "backward"
  </code></pre>