[Python-bugs-list] [ python-Bugs-654866 ] pickle and cPickle not equivalent
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 16 Dec 2002 15:13:42 -0800
Bugs item #654866, was opened at 2002-12-16 15:37
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=654866&group_id=5470
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Patrick K. O'Brien (pobrien)
Assigned to: Nobody/Anonymous (nobody)
Summary: pickle and cPickle not equivalent
Initial Comment:
Ignoring cosmetic differences, cPickle is not properly
pickling references to items in its memo, while pickle
does the right thing. Attached are two files, created by
the same process, one using pickle, the other cPickle.
I'll describe the important difference. First we pickle a
python graph (Bank) that contains references to
accounts. Then we pickle two transactions
(DepositOrWithdrawal) that contain references to one of
the accounts. The pickle version works fine and does a
get of the account pickled with the Bank:
(ccommands
DepositOrWithdrawal
p20
g2
Ntp21
R(dp22
g6
F1039911613.244611
sS'acnt'
p23
g13
sS'amount'
p24
I555
sbp25
.g0
(g20
g2
Ntp26
R(dp27
g6
F1039911618.384868
sg23
g13
sg24
I555
sbp28
.
But the cPickle version does it wrong. For the first
transaction it puts a new account instance with a get to
the dictionary of the account in the Bank. And on
pickling the second transaction it gets a reference to the
account instance from the first transaction:
(ccommands
DepositOrWithdrawal
p18
g3
NtRp19
(dp20
g7
F1039910911.252528
sS'acnt'
p21
(iaccount
Account
p22
g13
bsS'amount'
p23
I555
sb.g1
(g18
g3
NtRp24
(dp25
g7
F1039910918.068189
sg21
g22
sg23
I555
sb.
Let me know if you need more details than this.
----------------------------------------------------------------------
>Comment By: Patrick K. O'Brien (pobrien)
Date: 2002-12-16 17:13
Message:
Logged In: YES
user_id=179604
The classes are part of a sample app that someone else wrote.
Their lack of Python experience shows a bit. The system that
is doing the pickling was written by me. It is part of the
PyPerSyst project:
http://sourceforge.net/projects/pypersyst
You can check out the files from CVS. The storage.singlefile
module is where the pickling takes place. I commented out the
cPickle import and used pickle instead to find the problem.
The particular classes being pickled are defined in the files in
the sandbox/pobrien/plyonsbank directory: bank.py is the main
app and contains the Bank class, account.py contains the
Account class, command.py contains a variety of transaction
classes, and console.py is the interface.
The pypersyst package needs to be on the Python path, but
the sandbox stuff doesn't. Hope that helps.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2002-12-16 16:42
Message:
Logged In: YES
user_id=6380
I'd need the code for the classes before I can delve into this.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=654866&group_id=5470