title: Python script hanging when running in the background
body: <p>I have a Python script (run on 2.7) that behaves differently when I run it in from the command line versus the background.  When I run it from the terminal it runs as expected, the two threads run as daemons writing output to the window while the main loop waits for the quit command.  It runs forever until I enter quit:</p>
  
  <pre><code>python test.py
  </code></pre>
  
  <p>When the same program is run in the background, both threads run one time and then the program hangs (I've narrowed it down to the raw_input, I guess I made a incorrect assumption that the two threads would continue on even if run in the background and raw_input blocked the main one. e.g the two threads would basically run forever since there is no input in this scenario).</p>
  
  <pre><code>python test.py &amp;
  </code></pre>
  
  <p>My goal is to have one program with those loops running (potentially forever) but if I ran it from the terminal would accept input.</p>
  
  <p>In order to allow the program to run both from the terminal / in the background do I need to basically put an if statement before the raw_input that checks whether it's in the background or not or am I missing else that would help?</p>
  
  <pre><code>import sys
  import time
  from threading import Thread
  
  def threadOne():
      while True:
          print("Thread 1")
          time.sleep(1)
  
  def threadTwo():
      while True:
          print("Thread 2")
          time.sleep(1)
  
  # Run the threads in the background as daemons
  threadOne = Thread(target = threadOne)
  threadOne.daemon = True
  threadOne.start()
  
  threadTwo = Thread(target = threadTwo)
  threadTwo.daemon = True
  threadTwo.start()
  
  # Main input loop.  This will allow us to enter input.  The
  # threads will run forever unless "quit" is entered.  This
  # doesn't run when the program is run in the background (I
  # incorrectly assumed it would just run forever with no input 
  # ever being entered in that scenario).
  while True:
      userInput = ""
      userInput = raw_input("")
      time.sleep(1)
  
      # This should allow us to exit out
      if str(userInput) == "quit":
          sys.exit()
  </code></pre>