[IPython-dev] parallel: BaseException.message has been deprecated

Ondrej Certik ondrej@certik...
Wed Mar 18 21:52:27 CDT 2009


Hi,

if I run this code:

try:
    print mec.execute("get_tests()")
except:
    t, v, tr = sys.exc_info()
    print t
    print v
    print tr

I keep getting this traceback:

/home/ondrej/lib/lib/python/IPython/kernel/error.py:130:
DeprecationWarning: BaseException.message has been deprecated as of
Python 2.6
  s = str(self.message)
Traceback (most recent call last):
  File "t.py", line 27, in <module>
    print v
  File "/home/ondrej/lib/lib/python/IPython/kernel/error.py", line
133, in __str__
    s = s + '\n' + engine_str + str(et.__name__) + ': ' + str(ev)
AttributeError: 'str' object has no attribute '__name__'


So this patch fixes the deprecation warning:

=== modified file 'IPython/kernel/error.py'
--- IPython/kernel/error.py	2008-06-06 19:41:55 +0000
+++ IPython/kernel/error.py	2009-03-19 02:38:41 +0000
@@ -107,7 +107,7 @@
 class CompositeError(KernelError):
     def __init__(self, message, elist):
         Exception.__init__(self, *(message, elist))
-        self.message = message
+        self.msg = message
         self.elist = elist

     def _get_engine_str(self, ev):
@@ -127,7 +127,7 @@
             return tb

     def __str__(self):
-        s = str(self.message)
+        s = str(self.msg)
         for et, ev, etb in self.elist:
             engine_str = self._get_engine_str(ev)
             s = s + '\n' + engine_str + str(et.__name__) + ': ' + str(ev)




Now I only get this traceback:

  import struct, sets, time
<class 'IPython.kernel.error.CompositeError'>
Traceback (most recent call last):
  File "t.py", line 27, in <module>
    print v
  File "/home/ondrej/lib/lib/python/IPython/kernel/error.py", line
133, in __str__
    s = s + '\n' + engine_str + str(et.__name__) + ': ' + str(ev)
AttributeError: 'str' object has no attribute '__name__'

a quick debugging shows:

ipdb> p et
'exceptions.NameError'
ipdb> p type(et)
<type 'str'>

and str doesn't have any .__name__. So a fix could be along these lines:

-            s = s + '\n' + engine_str + str(et.__name__) + ': ' + str(ev)
+            s = s + '\n' + engine_str + et + ': ' + str(ev)


Now my script above shows the actual error:

one or more exceptions from call to method: execute
[Engine Exception]exceptions.NameError: global name '__IPYTHON__' is not defined
[Engine Exception]exceptions.NameError: global name '__IPYTHON__' is not defined
[Engine Exception]exceptions.NameError: global name '__IPYTHON__' is not defined
[Engine Exception]exceptions.NameError: global name '__IPYTHON__' is not defined
[Engine Exception]exceptions.NameError: global name '__IPYTHON__' is not defined
[Engine Exception]exceptions.NameError: global name '__IPYTHON__' is not defined
[Engine Exception]exceptions.NameError: global name '__IPYTHON__' is not defined
[Engine Exception]exceptions.NameError: global name '__IPYTHON__' is not defined


So I tried to get the line which goes wrong, by following the docs:

http://ipython.scipy.org/doc/nightly/html/parallel/parallel_multiengine.html#parallel-exceptions

by using .raise_exception()

try:
    print mec.execute("get_tests()")
except:
    t, v, tr = sys.exc_info()
    print t
    print v
    print tr
    print dir(v)
    v.raise_exception()

but I only got:

Traceback (most recent call last):
  File "t.py", line 30, in <module>
    v.raise_exception()
  File "/home/ondrej/lib/lib/python/IPython/kernel/error.py", line
157, in raise_exception
    raise et, ev, etb
TypeError: exceptions must be classes or instances, not str


So I'll try to debug it by some other methods to see what went wrong.

Ondrej


More information about the IPython-dev mailing list