threads and sockets

Josiah Carlson jcarlson at uci.edu
Wed Oct 13 14:49:58 EDT 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:
        try:
            select(sock, sock, sock, 1)
        except:
            #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