title: Gpio blocking in multi threading python
body: <p>For a school project I need to make a car that checks colours with a sensor connected to GPIO on a raspberry pi zero W using the RPi.GPIO library. At the same time I want to drive the car also with four gpio pins using the gpiozero library. The controlles for the movement are send to the pi zero via a python socket server. I have put all these processes in different threads but now it seems that I can't drive the car. It seems like Gpiozero is disabled and Rpi.Gpio only works.</p>
  
  <p>COLOUR SENSOR CODE</p>
  
  <pre><code>
      import RPi.GPIO as GPIO
      import time
  
      S2 = 26 #select color / S2
      S3 = 21 #select color / S3
      wave = 20 #sine wave proportional to light frequency / OUT
      pulses = 1000 #pulses to check, more pulses increase accuracy but decreases speed
  
      def setup():
          GPIO.setmode(GPIO.BCM)
          GPIO.setup(wave, GPIO.IN, pull_up_down=GPIO.PUD_UP)
          GPIO.setup(S2, GPIO.OUT)
          GPIO.setup(S3, GPIO.OUT)
  
      def getFrequency(color):
          if (color == 'red'):
              GPIO.output(S2, GPIO.LOW)
              GPIO.output(S3, GPIO.LOW)
          if (color == 'green'):
              GPIO.output(S2, GPIO.HIGH)
              GPIO.output(S3, GPIO.HIGH)
          if (color == 'blue'):
              GPIO.output(S2, GPIO.LOW)
              GPIO.output(S3, GPIO.HIGH)
          if (color == 'clear'):
              GPIO.output(S2, GPIO.HIGH)
              GPIO.output(S3, GPIO.LOW)
  
          startTime = time.time()
          for pulseCount in range(pulses):
              GPIO.wait_for_edge(wave, GPIO.FALLING)
          duration = time.time() - startTime
          frequency = wave / duration
          return frequency
  
      def endProgram():
          GPIO.cleanup()
  
      setup()
  
  </code></pre>
  MOVEMENT CODE 
  
  <pre><code>
      from gpiozero import Motor
  
      class Movement:
          #define pi zero pin numbers and pwm speed
          pin1 = 17 #forward
          pin2 = 18 #backward
          pin3 = 22 #left
          pin4 = 23 #right
          pwm = 1.0 #0.0 to 1.0
  
          motor = Motor(pin1, pin2, True)
          steer = Motor(pin3, pin4)
  
          # Set the pwm of the car
          def setPWM(self, pwm):
              self.pwm = pwm
  
          def forward(self):
              self.motor.forward(self.pwm)
  
          def backward(self):
              self.motor.backward(self.pwm)
  
          def halt(self):
              self.motor.stop()
  
          def right(self):
              self.steer.forward()
  
          def left(self):
              self.steer.backward()
  
          def straight(self):
              self.steer.stop()
  
  </code></pre>
  
  <p>In an other file I have these functions </p>
  
  <pre><code>
      def listen():
          print("Listening to commands")
          while True:
              msg = socket.receive()
              print("received: " + msg)
              try:    
                  if(msg == something):
                      movement.forward() #ect
              except:
                  print(msg)
  
      listening = Thread(target=listen)
      listening.start()
  
  </code></pre>
  
  <p>I let the code for the color sensor run in the main thread</p>
  
  <p>I expect that everything works as it should and the car drives forward and the colour sensor reads the right values</p>