Hacker News new | past | comments | ask | show | jobs | submit login
Python `select` module - well explained step by step (doughellmann.com)
41 points by tzury on Oct 3, 2010 | hide | past | favorite | 6 comments



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://scotdoyle.com/python-epoll-howto.html

* http://blog.urbanairship.com/blog/2010/08/24/c500k-in-action...

* http://www.metabrew.com/article/a-million-user-comet-applica...


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.


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.


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.


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


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: