title: select() on socket and another event mechanism
body: <p>I want to read from a socket when data is available and in the same thread I want to read items from a message queue like this:</p>
  
  <pre><code>while True:
      ready = select.select([some_socket, some_messagequeue], [], [])[0]
      if some_socket in ready:
          read_and_handle_data_from_socket()
      if some_messagequeue in ready:
          read_and_handle_data_from_messagequeue()
  </code></pre>
  
  <p>With other words: I want to abort <code>select()</code> as soon as the thread receives messages via some process internal messaging system.</p>
  
  <p>From what I have read now I found two approaches: <code>select</code>ing on the message-queue itself or creating a <code>os.pipe()</code> for aborting the <code>select()</code> but I didn't find a nice implementation yet.</p>
  
  <p><strong>Approach 1</strong>: There seem to be two <code>Queue</code> implementations: <code>multiprocessing.Queue</code> and <code>queue.Queue</code> (Python3). While <code>multiprocessing.Queue</code> has a <code>_reader</code> member which can be used with <code>select()</code> only <code>queue.Queue</code> allows arbitrary data structures to be queued without having to mess with the pickling.</p>
  
  <p><strong>Question:</strong> Is there a way to use <code>select()</code> on a <code>queue.Queue</code> as well?</p>
  
  <p><strong>Approach 2</strong>: would look like this:</p>
  
  <pre><code>import os, queue, select
  r, w = os.pipe()
  some_socket = 67  # FD to some other socket
  q = queue.Queue()
  def read_fd():
      while True:
          ready = select.select([r, some_socket], [], [])[0]
          if r in ready:
              os.read(r, 100)
              print('handle task: ', q.get())
          if some_socket in ready:
              print('socket has data')
  
  threading.Thread(target=read_fd, daemon=True).start()
  while True:
      q.put('some task')
      os.write(w, b'x')
      print('scheduled task')
      time.sleep(1)
  </code></pre>
  
  <p>And this works - but in my eyes this code is quite cumbersome and not very pythonic. <strong>Question:</strong> is there a nicer way to just send 'signals' through a <code>os.pipe</code> (or any other implementation)?</p>
  
  <p><strong>Approach 3..N</strong>: <strong>Question:</strong> how would you solve this? </p>
  
  <p>I know libraries like ZeroMQ but since I'm working on an embedded project I'd prefer a solution that comes with the native Python (3.3) distribution. And I think a there should be a solution as short as the first example - after all I just want to <em>abort</em> the <code>select()</code> if something happens on the message queue.</p>