[Tutor] basic threading question

richard kappler richkappler at gmail.com
Thu Jan 7 14:26:21 EST 2016


See previous posts on 'looping generator' for details about the code and
project.

The brief version, I am reading and parsing a data stream through a socket,
several actually. Each new connection spawns a thread that reads and
parses. Should the client close, I want the thread to terminate. Everything
I've read says you don't kill threads, but if the client closes, the socket
closes, and the thread is just sitting there, hanging.

If the socket.recv returns 0 bytes, the docs tell me that means the client
closed and therefore the server socket closes as well. If I do something in
the thread target function like:

        data_chunks = connection.recv(8192)
        if len(data_chunks) == 0:
             break

len(data_chunks)==0 tells me the socket is closed, but does the break kill
the thread? How do I prove that if it does?

regards, Richard


More information about the Tutor mailing list