fritzy/SleekXMPP — pull request #247 by anton-ryzhov (2013-07-01 07:09:25+00:00)
Title: Blocking queue get

I'm continuing (#244) to optimize main loops to reduce CPU usage in idle mode.

When we are using non-blocking Queue.get with timeout, underlying Condition doesn't lock for all timeout. It starts to lock and release frequently.

I've replaced non-blocking Queue.get to blocking one. Previously we've used timeout to break thread loop cycle on stopping event. Now I'm breaking loop by putting None into queues. Queue.get unblocks and thread react on stop flag.

After this we have only Scheduler loop with non-blocking get. But it have to be non-blocking with timeout for running tasks. Possible next step — not to split timeout to `wait_timeout` portions should decrease cpu usage too, but not so notably. I've left it as is right now.

I've benchmarked both of this improvements (#244 and current). I've started 3 `echo_client`s with original version (baf9aaf26c80c87e770cdf35b1fa4fe231663246), after #244 and after both of them.

9 hours of running with no incoming messages gave me this `ps aux`:
```
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user 1428 1.4 0.4 285720 14548 pts/0 Sl 01:10 6:56 python ./echo_client.py
user 1458 0.5 0.4 285736 14564 pts/0 Sl 01:10 2:45 python ./echo_client.py
user 1489 0.2 0.4 285736 14560 pts/0 Sl 01:10 0:59 python ./echo_client.py
```