mailRe: Pickling problems with the relax data storage singleton.


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Gary Thompson on November 23, 2007 - 09:15:
Edward d'Auvergne wrote:

Hi,

Sorry.  Unfortunately the message missed the mailing.  Would you be
able to resend it?

Thanks,

Edward


On Nov 22, 2007 10:58 AM, Gary Thompson <garyt@xxxxxxxxxxxxxxx> wrote:
Edward d'Auvergne wrote:

On Nov 22, 2007 9:54 AM, Gary Thompson <garyt@xxxxxxxxxxxxxxx> wrote:


Edward d'Auvergne wrote:



Chris and Gary,

Remember a long way back we had discussions about the following concept:

-----
class Data(dict):
 """The relax data storage object."""

[snip]

# Rebind the name Data with an instance to prevent accidental creation
# of multiple instances of the Data class
Data = Data()
-----



[snip]



Can you give some details of how it fails? Is there an exception or does
it just replace the Data sinleton instance with a class instance?
Anyway i will dig further later in the week


This can be seen by running the unit tests.  Just edit the file
data/__init__.py which contains the singleton and raname both
instances of Data2 to Data.  Then the unit test will give the relevent
message:

======================================================================
ERROR: The pickling and saving of the relax data storage singleton.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/nmr5/edau/relax/relax-1.3/test_suite/unit_tests/state_testing_base.py",
line 100, in test_save
  self.state.save_state(file='test')
File "/nmr5/edau/relax/relax-1.3/prompt/state.py", line 178, in save
  save_state(file=file, dir=dir, force=force, compress_type=compress_type)
File "/nmr5/edau/relax/relax-1.3/generic_fns/state.py", line 77, in save_state
  dump(relax_data_store, file, 1)
PicklingError: Can't pickle <class 'data.Data'>: it's not the same
object as data.Data

======================================================================

This looks like a possible namespace issue.  Maybe???




regards
gary

Of course one of the points here is that this isn't the only way to
write a singleton ;-)


Of course, but I think we should still go with the way we voted.  We
just need to work out how to pickle this thing.

Cheers,

Edward


--
Edward d'Auvergne
Website:  http://nmr-relax.com
Profile:  https://gna.org/users/bugman

.



Hi Ed

from looking at the error here I think the problem is that python
internally thinks that Data() is still the classes constructor and is
suprised to find that it is a different object...

I think the answer is on the following page
http://docs.python.org/lib/pickle-inst.html you need to define
__getstate__ and __setstate__ but...

Its Worse than that he's Dead Jim
---------------------------------

There is possibly more that you have to do here, we need to check what
happens if two state pickles are read in: do we get two different
singletons ! What happens if we read in a pickle after already creating
a Data object...

we definitley need to write some tests for these cases


regards
gary

--
-------------------------------------------------------------------
Dr Gary Thompson
Astbury Centre for Structural Molecular Biology,
University of Leeds, Astbury Building,
Leeds, LS2 9JT, West-Yorkshire, UK             Tel. +44-113-3433024
email: garyt@xxxxxxxxxxxxxxx                   Fax  +44-113-2331407
-------------------------------------------------------------------




.



--
-------------------------------------------------------------------
Dr Gary Thompson
Astbury Centre for Structural Molecular Biology,
University of Leeds, Astbury Building,
Leeds, LS2 9JT, West-Yorkshire, UK             Tel. +44-113-3433024
email: garyt@xxxxxxxxxxxxxxx                   Fax  +44-113-2331407
-------------------------------------------------------------------





Related Messages


Powered by MHonArc, Updated Mon Nov 26 03:41:22 2007