
Python `select` module - well explained step by step - tzury
http://www.doughellmann.com/PyMOTW/select/
======
metachris
Keep in mind that select basically sucks for handling more than a few sockets
-- it's slow and limited to max. 1024 concurrent sockets (unless you change
FD_SETSIZE and recompile everything, which may cause unexpected bugs).

An almost always better choice is using epoll -- it's usually faster and can
handle any number of concurrent sockets (up to a million and more).

* [http://docs.python.org/library/select.html#edge-and-level-tr...](http://docs.python.org/library/select.html#edge-and-level-trigger-polling-epoll-objects)

* <http://scotdoyle.com/python-epoll-howto.html>

* [http://blog.urbanairship.com/blog/2010/08/24/c500k-in-action...](http://blog.urbanairship.com/blog/2010/08/24/c500k-in-action-at-urban-airship/)

* [http://www.metabrew.com/article/a-million-user-comet-applica...](http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-3)

~~~
almost
This is assuming that performance is an issue, which I would guess is not the
case for at least 90% of uses. For most cases I'd say ease of use and cross
platform makes select "better" than epoll.

~~~
endgame
This is why I like libev, which has bindings to several languages (including
python). It picks the best backend for watching FDs on a given system (epoll,
select, ...). The support for timers, idle callbacks and so on is also very
handy.

------
rue
It is not _that_ well-explained, actually. Checking for output-ready status is
quite often a waste of time. An exceptional condition does not necessarily
mean an error (TCP OOB messages, though rarely used), and it is likewise
unnecessary for many if not most applications.

Python, like many languages, seems to just defer to the OS select(), so a good
read for parties interested are the man pages and maybe something like Beej's
Guide to Networking.

------
hartror
Well written article, I've never used select as Twisted casts a long shadow
and has always satisfied my needs.

~~~
pjscott
Personally, I stopped using Twisted as soon as I realized that I had just
written a factory factory. Your mileage may vary.

Have you looked at eventlet or gevent? They're libraries in Python for doing
single-threaded networking (like Twisted) but in a very lightweight and
pleasant way. They use coroutines, so you can usually write code as if it were
blocking, and you can use the standard library networking functions with non-
blocking magic sprinkled on top. I've found it to be remarkably
straightforward.

