Hi Lars,
Stackless does not really pickle a module. Probably you refer to my talk
at Europython 2011. You may want to look at the sPickle
(https://pypi.python.org/pypi/sPickle). It can pickle modules "by value"
or "by reference".
You wonder, why the pickler pickles a reference to your module. One
common but not obvious reason is a reference to the module's __dict__.
Pickling the dictionary of a module causes the pickler to pickle a
reference to the module object itself.
Module dictionaries are usually referenced as global namespace by
function- and frame-objects. Tasklets or exceptions contain references
to frames.
You wrote "the loaded model seems to use a pre-change class definition".
Probably you observe the following: if you pickle a tasklet, the tasklet
contains the list of frames on the stack. Each frame represents a
running function, but the frame does not reference the function object
but the code object of the function. Now code objects are always pickled
by value. Upon unpickling you get the old code objects. With other
words, you can't magically modify the code, that currently executes.
Pickling code objects by value is required, because local variables,
cells, code and the instruction pointer must be in an consistent state.
Cheers
Anselm
Am 09.01.2014 10:49, schrieb lars van Gemerden:
Hi all,
I seem to have problems with pickling and i was wondering whether it is
stackless related (i found a presentation by Anselm Kruis saying that
stackless pickles modules).
I found two problems that seem odd to me:
1) if i pickle-save my model, remove a class from my modules and then load
the save, sometimes the unpickler crashed even when the class is not used
in my model (it still looks for the removed class, although i see no reason
the unpickler needs it for the model i saved).
2) If i change a class after saving the model, and then load the model
again, the loaded model seems to use a pre-change class definition.
This means that during testing i need to recreate the model (which can be
quite complex) after any changes to the classes it uses (and even after
removing classes i don't use), even if the change should not influence the
saved and reloaded pickle in any way.
It also means that save files become much more brittle in any production
version of the program.
So my questions are, is this caused by stackless (compared to vanilla
python) and if so, what triggers the pickling of modules and how can i
influence that or use the vanilla version of pickle instead.
Cheers, Lars
Hi all,
I seem to have problems with pickling and i was wondering whether it is
stackless related (i found a presentation by Anselm Kruis saying that
stackless pickles modules).
I found two problems that seem odd to me:
1) if i pickle-save my model, remove a class from my modules and then
load the save, sometimes the unpickler crashed even when the class is
not used in my model (it still looks for the removed class, although i
see no reason the unpickler needs it for the model i saved).
2) If i change a class after saving the model, and then load the model
again, the loaded model seems to use a pre-change class definition.
This means that during testing i need to recreate the model (which can
be quite complex) after any changes to the classes it uses (and even
after removing classes i don't use), even if the change should not
influence the saved and reloaded pickle in any way.
It also means that save files become much more brittle in any production
version of the program.
So my questions are, is this caused by stackless (compared to vanilla
python) and if so, what triggers the pickling of modules and how can i
influence that or use the vanilla version of pickle instead.
Cheers, Lars
--
====================================
Lars van Gemerden
[email protected] <mailto:[email protected]>
+31 6 26 88 55 39
====================================
_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless
--
Dipl. Phys. Anselm Kruis science + computing ag
Senior Solution Architect Ingolstädter Str. 22
email [email protected] 80807 München, Germany
phone +49 89 356386 874 fax 737 www.science-computing.de
--
Vorstandsvorsitzender/Chairman of the board of management:
Gerd-Lothar Leonhart
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Michael Heinrichs,
Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/
Chairman of the Supervisory Board:
Philippe Miltin
Sitz/Registered Office: Tuebingen
Registergericht/Registration Court: Stuttgart
Registernummer/Commercial Register No.: HRB 382196
_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless