threads and sockets

Josiah Carlson jcarlson at
Wed Oct 13 20:49:58 CEST 2004

> > how can i stop a server socket running in a thread other than the main
> > thread? if the server socket was a local variable of the function started
> > by the child thread, would calling join work?
> Short answer: you can't, and join won't help. Use select on sockets, with a
> timeout, or use twisted.

More specifically:

def serverthread(sock):
    while not quit:
            select(sock, sock, sock, 1)
            #handle errors, but don't use a bare except in real code
    #close sock if necessary

 - Josiah

More information about the Python-list mailing list