Sylvain Prat
2013-02-01 19:27:08 UTC
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
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eby-sarna.com/pipermail/peak/attachments/20130201/fbaf1991/attachment.html
Sylvain PRAT
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eby-sarna.com/pipermail/peak/attachments/20130201/fbaf1991/attachment.html