<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 &quot;TypeError: can&#39;t pickle lock objects&quot;. I&#39;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&#39;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&#39;m not sure how the problem can be fixed. I&#39;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, &#39;arg == 0&#39;)</div><div>
    def run_3(self, arg):</div><div>        return 0</div><div><br></div><div><br></div><div>if __name__ == &#39;__main__&#39;:</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 &quot;TypeError: can&#39;t pickle lock objects&quot;</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>