<div dir="ltr">maybe double but i got a mail bounce ..<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">lars van Gemerden</b> <span dir="ltr"><<a href="mailto:lars@rational-it.com">lars@rational-it.com</a>></span><br>
Date: Thu, Oct 3, 2013 at 6:15 PM<br>Subject: Re: [Stackless] deepcopying (pickling) channels<br>To: The Stackless Python Mailing List <<a href="mailto:stackless@stackless.com">stackless@stackless.com</a>><br><br><br>
<div dir="ltr">actually both give an error. The only thing different is the error message. with pickle the code would be:<div><br></div><div>---------------------------------------------------------------------------</div>

<div><div>import stackless, pickle</div><div class="im"><div><br></div><div>class Test(object):</div><div>    def __init__(self):</div><div>        self.channel = stackless.channel()</div><div>        </div><div>    def run(self):</div>
<div>
        stackless.tasklet(self.sender)()</div><div>        stackless.tasklet(self.receiver)()</div><div>        stackless.run()</div><div>        </div><div>    def sender(self):</div><div>        counter = 0</div><div>        while counter < 10:</div>

<div>            self.channel.send(counter)</div><div>            counter += 1</div><div>        </div><div>    def receiver(self):</div><div>        counter = 0</div><div>        while counter < 12:</div><div>            counter = self.channel.receive()</div>

<div>            print counter,</div><div>        print "done"</div><div>            </div><div>if __name__ == "__main__":</div><div>    </div><div>    t = Test()</div><div>    t.run()</div><div>    t.channel = None</div>

</div><div>    s = pickle.dumps(t) #OK</div><div>    </div><div>    t = Test()</div><div>    t.run()</div><div>    s = pickle.dumps(t) #ERROR</div></div><div>-----------------------------------------------------------------------------</div>

<div>and the error:</div><div><br></div><div>pickle.PicklingError: Can't pickle <type 'function'>: it's not found as __builtin__.function<br></div><div><br></div><div>otherwise the error behavior is the same as decribed above.</div>

<div><br></div><div>Cheers, Lars</div><div><br></div><div>(as far as i have read and tested a bit, deepcopy allows more to be copied then pickle, but cPickle is faster, so i have my own deepcopy:</div><div><br></div><div>

def deepcopy(obj):<br></div><div>    try:</div><div>        return cPickle.loads(cPickle.dumps(obj, -1))</div><div>    except PicklingError:</div><div>        return copy.deepcopy(obj)</div><div>)<br></div></div><div class="gmail_extra">
<div><div class="h5">
<br><br><div class="gmail_quote">On Thu, Oct 3, 2013 at 5:19 AM, Richard Tew <span dir="ltr"><<a href="mailto:richard.m.tew@gmail.com" target="_blank">richard.m.tew@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I'm a little confused.  Are you pickling the tasklets, or copying<br>
them?  These are different things to Python.<br>
<br>
As far as I know using copy or deepcopy has never been supported for<br>
tasklets and therefore channels.<br>
<br>
Pickling however, is another matter.<br>
<br>
Cheers,<br>
Richard.<br>
<br>
_______________________________________________<br>
Stackless mailing list<br>
<a href="mailto:Stackless@stackless.com" target="_blank">Stackless@stackless.com</a><br>
<a href="http://www.stackless.com/mailman/listinfo/stackless" target="_blank">http://www.stackless.com/mailman/listinfo/stackless</a><br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><div class="im">-- <br>====================================<br>Lars van Gemerden<br><a href="mailto:lars@rational-it.com" target="_blank">lars@rational-it.com</a><br>
<a href="tel:%2B31%206%2026%2088%2055%2039" value="+31626885539" target="_blank">+31 6 26 88 55 39</a><br>====================================
</div></div>
</div><br><br clear="all"><div><br></div>-- <br>====================================<br>Lars van Gemerden<br><a href="mailto:lars@rational-it.com">lars@rational-it.com</a><br>+31 6 26 88 55 39<br>====================================
</div>