<div dir="ltr"><div style>Hello,</div><div style><br></div><div style>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.</div>
<div style><br></div><div style>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.</div>
<div style><br></div><div style>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.</div>
<div style><br></div><div style>Can someone help? Thanks in advance!</div><div style><br></div><div style>Here is a test case that triggers the problem:</div><div style><br></div><div>-----</div><div><br></div><div><div>from peak.rules import when</div>
<div>import cPickle as pickle</div><div><br></div><div><br></div><div>class Test(object):</div><div> def run(self, arg):</div><div> return 42</div><div><br></div><div> @when(run, 'arg == 0')</div><div>
def run_3(self, arg):</div><div> return 0</div><div><br></div><div><br></div><div>if __name__ == '__main__':</div><div> run = Test().run</div><div><br></div><div> assert run(3) == 42</div><div> assert run(0) == 0</div>
<div><br></div><div> s = pickle.dumps(run) # raises a "TypeError: can't pickle lock objects"</div><div> run = pickle.loads(s)</div><div><br></div><div> assert run(3) == 42</div><div> assert run(0) == 0</div>
</div><div><br></div><div><br></div>-- <br>Sylvain PRAT<br><br></div>