python wait queue and socket in single thread
<p>my app is a tcp server, using epoll to wait for requests.<br>
i wanna wait for a queue in the same loop.<br>
that is: <strong><code>wake up the thread either socket r/w is available or queue is not empty.</code></strong></p>

<p>i surely googled a lot, but none good solution found.<br>
i've thought about several ways to work around it:</p>

<ol>
<li><p>set a timeout(e.g.0.5) for epoll.wait, and then queue.get_nowait until empty.
in this way, cpu resource is wasted even if nothing to deal with.
and it's not that real-time.</p></li>
<li><p>use domain socket instead of queue, so that epoll can wait for both.
in this way, sender has to convert the python-object to string/binary data to
transfer (and receiver versa), which is boring.</p></li>
</ol>

<p>--- none of them satisfy me.</p>

<p>i wonder if epoll can wait for Event?
 --so that i can event.set() after queue.put().
or</p>

<p>Is there a good way to solve my problem?</p>

<p>THANKS!</p>

<p>It sounds like you should look into non-blocking sockets.</p>

<p><a href="https://docs.python.org/2/howto/sockets.html#non-blocking-sockets" rel="nofollow">https://docs.python.org/2/howto/sockets.html#non-blocking-sockets</a></p>

python multithreading sockets queue epoll