[PEAK] Missing pickling support for generic methods

Hervé Coatanhay herve.coatanhay at gmail.com
Fri Feb 1 18:32:04 EST 2013


Hi,

As a note, the `lock` issue occurs with stackless python, which allows
instancemethod pickling. In standard cpython it is "TypeError: can't pickle
instancemethod objects" obviously.

--
Hervé
On Fri, Feb 1, 2013 at 7:19 PM, Sylvain Prat <sylvain.prat at gmail.com> wrote:

> Hello,
>
> I recently encountered a pickling problem with peak.rules. The generic
> methods do not pickle: they raise a "TypeError: can't pickle lock objects".
> I've dugg into the code with a colleague and we found that the Dispatching
> object that registers the implementations of the method is pickled and
> since it contains a lock, the pickling fails.
>
> It's a little annoying because it prevents us from using generic methods
> as action callbacks (actions performed when e.g. we click on a link in a
> web page) in Nagare Web applications because Nagare pickles them in the
> user session.
>
> I'm not sure how the problem can be fixed. I'm wondering if the
> Dispatching object should be pickled (or not) and if regenerations have to
> be triggered on pickling/depickling.
>
> Can someone help? Thanks in advance!
>
> Here is a test case that triggers the problem:
>
> -----
>
> from peak.rules import when
> import cPickle as pickle
>
>
> class Test(object):
>     def run(self, arg):
>         return 42
>
>     @when(run, 'arg == 0')
>     def run_3(self, arg):
>         return 0
>
>
> if __name__ == '__main__':
>     run = Test().run
>
>     assert run(3) == 42
>     assert run(0) == 0
>
>     s = pickle.dumps(run)  # raises a "TypeError: can't pickle lock
> objects"
>     run = pickle.loads(s)
>
>     assert run(3) == 42
>     assert run(0) == 0
>
>
> --
> Sylvain PRAT
>
>
> _______________________________________________
> PEAK mailing list
> PEAK at eby-sarna.com
> http://www.eby-sarna.com/mailman/listinfo/peak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eby-sarna.com/pipermail/peak/attachments/20130202/985ae223/attachment.html


More information about the PEAK mailing list