Hello.<br><br>I was going to write a log mail to ask for help, but i have already resolved it with lots and increible lots of hours, so i send what the problem was and how i have solved it for any other who haves the same problem.
<br><br>I have a method called tryconnect which is called from a thread in python:<br><br>self._connect_thread = DepThread( target=self.tryConnect, args=() )<br>self._connect_thread.start()<br><br>inside the tryconnect i call connect and manage its exceptions.
<br>When an exception occurs i call a callback which shows the info to the user.<br><br>I got on the need to ask the user to accept a new hostkey when it is not on the hostkeys list.<br>So i made my own Policy:<br><br>class HostkeyUserRejectedException(
paramiko.AuthenticationException):<br> """<br> Exception raised when the hostkey is rejected by the user.<br> """<br> pass<br>class Policy_with_callback(paramiko.AutoAddPolicy, paramiko.RejectPolicy
):<br> def __init__(self,callback):<br> self.callback = callback<br> <br> def missing_host_key(self, client, hostname, key):<br> """<br> Called when an SSHClient receives a server key for a server that
<br> isn't in either the system or local HostKeys object. To accept<br> the key, simply return. To reject, raise an exception (which will<br> be passed to the calling application).<br> """
<br> if not self.callback:<br> raise Exception("No callback specified. When using method -1 to validate hostkeys you should use a callback.")<br><br> try:<br> ret = self.callback
(client, hostname, key)<br> except Exception, error:<br> raise Exception("An error ocurred when calling the policy_callback: "+error)<br> if ret:<br> try:<br>
paramiko.AutoAddPolicy.missing_host_key(self,client,hostname,key)<br> except IOError,error:<br> os.mkdir( os.path.expanduser('~/.ssh') )<br> return<br> try:<br>
paramiko.RejectPolicy.missing_host_key(self,client,hostname,key)<br> except paramiko.SSHException,error:<br> raise HostkeyUserRejectedException('The user rejected to accept the hostkey for %s' % hostname)
<br><br><br>This policy uses a callback to make another code ask the user in different ways, like only in the console or with gtk.<br>The problem was when i reject intentionally the key, even with RejectPolicy the raised exception goes to my tryconnect method and is wrapped there, but the transport is still alive and waiting for a response to happen, which never occurs becouse i have wrapped the exception.
<br>This makes the tryconnect-thread eternal. Never ends.<br><br>To fix this i call a single method on every exception handler called self.selfdestruct:<br><br> except HostkeyUserRejectedException, error:<br>
self.selfdestruct("HostkeyUserRejectedException",error)<br> except HostkeyAutoRejectedException, error:<br> self.selfdestruct("HostkeyAutoRejectedException",error)<br> except paramiko.PasswordRequiredException
, error:<br> self.selfdestruct("PasswordRequiredException",error)<br><br><br> def selfdestruct(self,errtype,error):<br> self.error_calls(errtype+": "+error[0])<br> self.onconnect_callback
(self,errtype)<br> if not self._isconnected:<br> self.client.close()<br> del self.client<br><br><br><br><br>