title: Python: How to interrupt raw_input() in other thread
body: <p>I am writing a simple client-server program in python. In the client program, I am creating two threads (using Python's threading module), one for receiving, one for sending. The receiving thread continuously receives strings from the server side; while the sending thread continuously listens to the user input (using raw_input()) and send it to the server side. The two threads communicate using a Queue (which is natively synchronized, LIKE!).</p>
  
  <p>The basic logic is like following:</p>
  
  <p>Receiving thread:</p>
  
  <pre><code>global queue = Queue.Queue(0)
  
  def run(self):
      while 1:
          receive a string from the server side
          if the string is QUIT signal:
              sys.exit()
          else:
              put it into the global queue
  </code></pre>
  
  <p>Sending thread:</p>
  
  <pre><code>def run(self):
      while 1:
          str = raw_input()
          send str to the server side
          fetch an element from the global queue
          deal with the element
  </code></pre>
  
  <p>As you can see, in the receiving thread, I have a if condition to test whether the server has sent a "QUIT signal" to the client. If it has, then I want the whole program to stop. </p>
  
  <p>The problem here is that for most of its time, the sending thread is blocked by "raw_input()" and waiting for the user input. When it is blocked, calling "sys.exit()" from the other thread (receiving thread) will not terminate the sending thread immediately. The sending thread has to wait for the user to type something and hit the enter button. </p>
  
  <p>Could anybody inspire me how to get around with this? I do not mind using alternatives of "raw_input()". Actually I do not even mind changing the whole structure.</p>
  
  <p>-------------EDIT-------------</p>
  
  <p>I am running this on a linux machine, and my Python version is 2.7.5</p>