473,394 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Kill thread or at least socket.getaddrinfo

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?
Mar 26 '07 #1
3 2852
On Mar 26, 10:53 am, Thomas Dybdahl Ahle <lob...@gmail.comwrote:
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

Mar 26 '07 #2
On 26 Mar., 18:08, kyoso...@gmail.com wrote:
you know the pid, you can kill it, but that's not always a
clean way of accomplishing the task.
So I have to open the connection in a new process... Sigh.. How I hate
this part of Python.

Apr 10 '07 #3
On 10 Apr 2007 11:07:51 -0700, lo****@gmail.com <lo****@gmail.comwrote:
On 26 Mar., 18:08, kyoso...@gmail.com wrote:
you know the pid, you can kill it, but that's not always a
clean way of accomplishing the task.

So I have to open the connection in a new process... Sigh.. How I hate
this part of Python.
This isn't a python problem. You can't cleanly or safely kill threads,
period. If you have to use blocking functions like this (you don't,
you might consider using Twisted for your networking instead) the way
you "cancel" it is to just stop waiting for the response and discard
the response (or error) when it eventually comes.
--
http://mail.python.org/mailman/listinfo/python-list
Apr 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: phil | last post by:
And sorry I got ticked, frustrating week >And I could help more, being fairly experienced with >threading issues and race conditions and such, but >as I tried to indicate in the first place,...
5
by: Blatwurst | last post by:
I'm trying to implement a simple server in C#. I want to do the classic thing of spinning off a thread that just blocks in a Socket.Accept() call until a request comes in. At that point, the...
0
by: mumebuhi | last post by:
I removed my previous post about this topic because I apparently have pasted the wrong code. Sorry for the confusion and thanks for being patient. I am having problem to kill the following...
3
by: Salvatore Di Fazio | last post by:
Hi guys, when I close the application I get the following error: ----------------------------- Traceback (most recent call last): File "main.py", line 88, in <module> while exit : pass...
1
by: mirandacascade | last post by:
I noticed the following lines from the connect() method of the HTTPConnection class within httplib: for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): af, socktype,...
2
by: John Nagle | last post by:
Here's a strange little bug. "socket.getaddrinfo" blows up if given a bad domain name containing ".." in Unicode. The same string in ASCII produces the correct "gaierror" exception. Actually,...
18
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do...
20
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
John Dohn wrote: When I do this, I put a special value in the queue (like None) and in the worker thread, check for the special value and exit if found. Threads can also be marked as "daemon...
1
by: Karl Chen | last post by:
I've discovered that since glibc 2.3.2, getaddrinfo(3) supports a useful flag called AI_ADDRCONFIG. It turns off AAAA lookups if the machine isn't configured for IPv6 (and similarly for IPv4,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.