[Tutor] How to kill a thread

Peter Otten __peter__ at web.de
Tue Nov 24 04:09:01 EST 2015


CMG Thrissur wrote:

> Thank you all.  i have pasted the code on pastebin.
> 
> http://pastebin.com/embed_iframe.php?i=kHAUJQC2
> 
> My one main question in the code is that there are times when my thread
> using pythonwhois hangs up the process by statying active very long
> time.  can i hope for a better solution to this problem.

> result = pythonwhois.get_whois(workurl)

I don't know pythonwhois. Does it invoke the whois commandline tool or 
implement the protocol itself?

If it implements the protocol you can try and set a timeout, e. g.

import socket
socket.setdefaulttimeout(1)

If it uses subprocess to invoke whois and uses the communicate() method to 
fetch the data you can tweak the code and provide a timeout, see

https://docs.python.org/dev/library/subprocess.html#subprocess.Popen.communicate

If none of the above suggestions work tell us the exact Python version you 
are using and provide a link to the pythonwhois module so that we can try to 
come up with something else.



More information about the Tutor mailing list