title: Run function in background and continue with program
body: <p>I am trying to run a function in the background, whilst continuing with said code in python.</p>
  
  <p>The function I want to run in the background is from <code>socket</code>. Looking for specific data to cut the program off.</p>
  
  <p>Here is the function:</p>
  
  <pre><code>def receive():
      host = ""
      port = 13000
      buf = 1024
      addr = (host,port)
      Sock = socket(AF_INET, SOCK_DGRAM)
      Sock.bind(addr)
      (data, addr) = Sock.recvfrom(buf)
      return data
  </code></pre>
  
  <p>Here is the code I want to run:</p>
  
  <pre><code>while True:
      r = receive()
      if r == "stop":
          break
      #Cannot get past here, because of the function running.
      #Should loop over and over, until stop data is received
      print "Running program"
  </code></pre>
  
  <p>I have tried threading, with <code>r = threading.Thread(target=receive())</code> with no joy.</p>