On Nov 27, 2007 7:59 PM, Edward d'Auvergne <edward.dauvergne@xxxxxxxxx> wrote:
On Nov 27, 2007 12:21 AM, Chris MacRaild <macraild@xxxxxxxxxxx> wrote:
One solution is to change names just before we pickle, then change
back after unpickling.
saveData = Data
Data = saveData.__class__
should restore sanity, and allow:
pickle.dump(saveData, file)
It is a pretty crude hack, however, and as Gary says, raises lots of
questions as to what will happen if a state is loaded on top of the
existing, etc...
I've tried the suggestion but the unit test gives:
======================================================================
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 104, in test_save
self.state.save_state(state=self.tmp_file)
File "/nmr5/edau/relax/relax-1.3/generic_fns/state.py", line 77, in
save_state
save_store = relax_data_store
UnboundLocalError: local variable 'relax_data_store' referenced before
assignment
======================================================================
Can you show me the context of this error - UnboundLocal looks to me
like an implimentation issue rather than a fundamental problem with
the approach.
Here is an svn diff of the 1.3 line at r4066.
Index: generic_fns/state.py
===================================================================
--- generic_fns/state.py (revision 4066)
+++ generic_fns/state.py (working copy)
@@ -73,6 +73,10 @@
# Open the file for writing.
file = open_write_file(file_name=state, dir=dir_name,
force=force, compress_type=compress_type)
+ # Alias the singleton.
+ store_alias = relax_data_store
+ relax_data_store = store_alias.__class__
+
# Pickle the data class and write it to file
dump(relax_data_store, file, 1)
We want to pickle the Data instance, not the class, so the last line
here should be:
dump(store_alias, file, 1)
That said I've no idea why its throwing an UnboundLocalError
Chris