[IronPython] pickling exceptions and differences between IronPythonand cpython

Bruce Christensen t-bruch at microsoft.com
Fri Jul 14 18:34:12 CEST 2006


Thanks for the feedback! We should definitely support pickling
exceptions that originated as CLR exceptions. I've opened
http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkIt
emId=945 to track it.

--Bruce

-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Jason Ferrara
Sent: Friday, July 14, 2006 8:48 AM
To: users at lists.ironpython.com
Subject: [IronPython] pickling exceptions and differences between
IronPythonand cpython

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."
 >>>




_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list