From: mk on

Exception in thread Thread-9 (most likely raised during interpreter
shutdown):
Traceback (most recent call last):
File "/usr/local/lib/python2.6/threading.py", line 522, in
__bootstrap_inner
File "/var/www/html/cssh.py", line 875, in run
File "/var/www/html/cssh.py", line 617, in ssh_connect
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute
'BadAuthenticationType'


This happens on interpreter shutdown, even though I do try to catch the
AttributeError exception:

try:
fake = paramiko.BadAuthenticationType
try:
self.conobj.connect(self.ip, username=self.username,
key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout)
loginsuccess = True
except paramiko.BadAuthenticationType, e: # this is line 617
self.conerror = str(e)
except paramiko.SSHException, e:
self.conerror = str(e)
except socket.timeout, e:
self.conerror = str(e)
except socket.error, e:
self.conerror = str(e)
except AttributeError:
# this happens on interpreter shutdown
self.conerror = 'shutdown'


It's clear what happens: paramiko gets its attributes cleared or the
module perhaps gets unloaded and as result "paramiko" label leads to
None, which obviously has no attribute BadAuthenticationType.

However, even though this is surrounded by try .. except AttributeError
block, it evidently isn't catch. How to catch that exception? Or at
least preven displaying this message?

Regards,
mk

From: Chris Rebert on
On Tue, Feb 2, 2010 at 3:20 AM, mk <mrkafk(a)gmail.com> wrote:
> Exception in thread Thread-9 (most likely raised during interpreter
> shutdown):
> Traceback (most recent call last):
>  File "/usr/local/lib/python2.6/threading.py", line 522, in
> __bootstrap_inner
>  File "/var/www/html/cssh.py", line 875, in run
>  File "/var/www/html/cssh.py", line 617, in ssh_connect
> <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute
> 'BadAuthenticationType'
>
>
> This happens on interpreter shutdown, even though I do try to catch the
> AttributeError exception:
>
> try:
>    fake = paramiko.BadAuthenticationType
>    try:
>        self.conobj.connect(self.ip, username=self.username,
> key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout)
>        loginsuccess = True
>    except paramiko.BadAuthenticationType, e: # this is line 617
>        self.conerror = str(e)
>    except paramiko.SSHException, e:
>        self.conerror = str(e)
>    except socket.timeout, e:
>        self.conerror = str(e)
>    except socket.error, e:
>        self.conerror = str(e)
> except AttributeError:
>    # this happens on interpreter shutdown
>    self.conerror = 'shutdown'
>
>
> It's clear what happens: paramiko gets its attributes cleared or the module
> perhaps gets unloaded and as result "paramiko" label leads to None, which
> obviously has no attribute BadAuthenticationType.
>
> However, even though this is surrounded by try .. except AttributeError
> block, it evidently isn't catch. How to catch that exception? Or at least
> preven displaying this message?

Let's see if psychic debugging works...at 4 am...
Pure conjecture: Do you have something like the following elsewhere in
your code?:

try:
#code
except SomeError, AttributeError:
#code

For why this causes problems, consider:

except SomeError, e:
vs.
except SomeError, SomeOtherError:

Example:
try:
raise IndexError
except IndexError, IOError:
pass
print repr(IOError) #==> IndexError()

Hence, in your case, `AttributeError` may no longer refer to
AttributeError. You can check this by adding a `print
repr(AttributeError)` at the right place in your code.
I further conjecture that pyflakes/pychecker/etc. might issue a
warning about the offending bit of code.


"Third Option" solution: Since you take the same action no matter the
exception's type, have you considered simplifying your code to:

fake = paramiko.BadAuthenticationType
try:
self.conobj.connect(self.ip, username=self.username,
key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout)
loginsuccess = True
except Exception, e:
self.conerror = str(e)

Cheers,
Chris
--
http://tvtropes.org/pmwiki/pmwiki.php/Main/TakeAThirdOption
http://blog.rebertia.com
From: Gabriel Genellina on
En Tue, 02 Feb 2010 08:20:34 -0300, mk <mrkafk(a)gmail.com> escribi�:

> Exception in thread Thread-9 (most likely raised during interpreter
> shutdown):
> Traceback (most recent call last):
> File "/var/www/html/cssh.py", line 617, in ssh_connect
> <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute
> 'BadAuthenticationType'

So you started several threads, and one of them was in them middle of
connecting to somewhere when the program exited, correct?

> This happens on interpreter shutdown, even though I do try to catch the
> AttributeError exception:
>
> try:
> fake = paramiko.BadAuthenticationType
> try:
> self.conobj.connect(self.ip, username=self.username,
> key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout)
> loginsuccess = True
> except paramiko.BadAuthenticationType, e: # this is line 617
> self.conerror = str(e)
> except paramiko.SSHException, e:
> self.conerror = str(e)
> except socket.timeout, e:
> self.conerror = str(e)
> except socket.error, e:
> self.conerror = str(e)
> except AttributeError:
> # this happens on interpreter shutdown
> self.conerror = 'shutdown'
>
>
> It's clear what happens: paramiko gets its attributes cleared or the
> module perhaps gets unloaded and as result "paramiko" label leads to
> None, which obviously has no attribute BadAuthenticationType.

As part of the interpreter shutdown procedure, module globals are set to
None. Code that might be executed in those very precarious circumstances
should NOT reference any globals.

> However, even though this is surrounded by try .. except AttributeError
> block, it evidently isn't catch. How to catch that exception? Or at
> least preven displaying this message?

You could keep a local reference to those global names; by example, by
adding 'fake' default arguments:

def ssh_connect(self, other, arguments,
paramiko=paramiko, socket=socket):
...

or perhaps:

def ssh_connect(self, other, arguments):
BadAuthenticationType = paramiko.BadAuthenticationType
socket_timeout = socket.timeout
try:
...
except BadAuthenticationType, e:
...
except socket_timeout, e:
...

--
Gabriel Genellina

 | 
Pages: 1
Prev: online shopping
Next: ANN: GMPY 1.11 released