Advice on sockets and threads
Andrew Bennetts
andrew-pythonlist at puzzling.org
Wed May 21 20:43:15 EDT 2003
On Wed, May 21, 2003 at 05:20:24PM +0100, Gon?alo Rodrigues wrote:
> I have a class Session which is basically a thread (that is, it derives
> from threading.Thread) controlling a socket. The run method is basically
> a loop of the form:
Why are you writing your own networking framework? There are plenty for
python already:
- SocketServer (simple, in the standard library),
- asyncore (doesn't require threads, in the standard library),
- Twisted (sort of like asyncore on steroids, not in standard library).
My recommendation would be to use Twisted -- it is easier and more
powerful than asyncore, and already has protocols like telnet (and many,
many others) implemented for you. Writing a cross-platform select loop that
correctly interprets all the various error conditions is tricky; don't
reinvent the wheel.
-Andrew.
More information about the Python-list
mailing list