socket.accept()
Andrew Bennetts
andrew-pythonlist at puzzling.org
Mon Feb 10 20:59:20 EST 2003
On Tue, Feb 11, 2003 at 12:43:59AM +0100, marco wrote:
> very much simplified a function looks like this:
>
> def run():
> mysocket = socket.socket(blabla)
> mysocket.bind(blabla)
> mysocket.listen(1)
> while 1:
> newsocket, addr = mysocket.accept()
> # and so on...
>
> now this loop is in a thread which, once started, will
> never die. since a thread must (?) be killed at the
> end of the program i do have a problem, because the
> program just doesn't exit
> how can i stopp the .accept()?
>
> any help would be appreciated
Two suggestions:
If a threading.Thread is "daemonic", the program can finish without you
needing to stop the thread. Look at the "setDaemonic" method in the docs.
Secondly, if your server is even slightly complex, I strongly recommend
using a prewritten socket framework, rather than doing it yourself. I
personally prefer Twisted <http://twistedmatrix.com/>, but SocketServer or
asyncore may also be sufficient for your needs.
-Andrew.
More information about the Python-list
mailing list