<div>Hi,</div><div><br></div>As a note, the `lock` issue occurs with stackless python, which allows instancemethod pickling. In standard cpython it is &quot;TypeError: can&#39;t pickle instancemethod objects&quot; obviously.<div>
<br></div><div>--</div><div>Hervé<br><div class="gmail_quote">On Fri, Feb 1, 2013 at 7:19 PM, Sylvain Prat <span dir="ltr">&lt;<a href="mailto:sylvain.prat@gmail.com" target="_blank">sylvain.prat@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hello,</div><div><br></div><div>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><br></div><div>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><br></div><div>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><br></div><div>Can someone help? Thanks in advance!</div><div><br></div><div>Here is a test case that triggers the problem:</div><div><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>
<span class="HOEnZb"><font color="#888888">
</font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div>-- <br>Sylvain PRAT<br><br></font></span></div>
<br>_______________________________________________<br>
PEAK mailing list<br>
<a href="mailto:PEAK@eby-sarna.com">PEAK@eby-sarna.com</a><br>
<a href="http://www.eby-sarna.com/mailman/listinfo/peak" target="_blank">http://www.eby-sarna.com/mailman/listinfo/peak</a></blockquote></div></div>