[IronPython] pickling exceptions and differences between IronPython and cpython

Jason Ferrara jason.ferrara at jacquette.com
Fri Jul 14 17:48:07 CEST 2006


Using the pickle modules from cpython to pickle built in exceptions  
fails under IronPython because IronPython adds a clsException  
attribute which pickle can't handle. And example is below.

Should this be considered a bug?


IronPython 1.0.60712 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
 >>> import pickle
 >>> a=[]
 >>> try:
...     a[4]
... except Exception, e:
...     pickle.dumps(e)
...
Traceback (most recent call last):
   File , line 0, in <stdin>##43
   File z:\iptest\pickle.py, line 1386, in dumps
   File z:\iptest\pickle.py, line 231, in dump
   File z:\iptest\pickle.py, line 293, in save
   File z:\iptest\pickle.py, line 739, in save_inst
   File z:\iptest\pickle.py, line 293, in save
   File z:\iptest\pickle.py, line 663, in save_dict
   File z:\iptest\pickle.py, line 677, in _batch_setitems
   File z:\iptest\pickle.py, line 313, in save
TypeError: can't pickle IndexOutOfRangeException instance (non- 
default __reduce__ needed)
 >>> pickle.dumps(e.clsException)
Traceback (most recent call last):
   File , line 0, in <stdin>##72
   File z:\iptest\pickle.py, line 1386, in dumps
   File z:\iptest\pickle.py, line 231, in dump
   File z:\iptest\pickle.py, line 313, in save
TypeError: can't pickle IndexOutOfRangeException instance (non- 
default __reduce__ needed)
 >>> del e.clsException
 >>> pickle.dumps(e)
"(iexceptions\nIndexError\np0\n(dp1\nS'msg'\np2\nS'index out of  
range: 4'\np3\nsS'args'\np4\n(g3\ntp5\nsb."
 >>>


while in cpython:

Python 2.4.2 (#1, Jun 14 2006, 09:51:02)
[GCC 4.0.1 (Apple Computer, Inc. build 5247)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import pickle
 >>> a=[]
 >>> try:
...     a[4]
... except Exception, e:
...     pickle.dumps(e)
...
"(iexceptions\nIndexError\np0\n(dp1\nS'args'\np2\n(S'list index out  
of range'\np3\ntp4\nsb."
 >>>







More information about the Ironpython-users mailing list