Kill thread or at least socket.getaddrinfo

kyosohma at gmail.com kyosohma at gmail.com
Mon Mar 26 12:08:16 EDT 2007


On Mar 26, 10:53 am, Thomas Dybdahl Ahle <lob... at gmail.com> wrote:
> Hi, I'm writing an application that connects to the internet.
> Something like this:
>
> for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
>     af, socktype, proto, canonname, sa = res
>     try:
>         self.sock = socket.socket(af, socktype, proto)
>
> Now if the user press the cancel button, I'd like the connection to
> imidiatly stop. I run
> self.sock.shutdown(socket.SHUT_RDWR)
> self.sock.close()
> Dunno if they are both nessesary. I normaly use only the first, but it
> makes no difference to use both.
>
> If python is at the actual connection in socket.socket( this work fine,
> but if python is at calling socket.getaddrinfo(, it doesn't stop.
>
> I also can't kill the thread, as it is afaik not a possibility in python.
> Is there any other way to do this?


This is addressed to some degree on a wxPython wiki at:

http://wiki.wxpython.org/index.cgi/LongRunningTasks

I think you can also use the join() method. I've also heard that if
you know the pid, you can kill it, but that's not always a clean way
of accomplishing the task.

Mike




More information about the Python-list mailing list