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? 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
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
|
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...
| |