<div dir="ltr">I am reasonably familiar with pickle (e.g. i know you cant pickle most functions), but this is pretty stackless specific: why can i pickle an empty channel, but not a sending/receiving channel?<div><br></div>
<div>Cheers, Lars</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Oct 7, 2013 at 7:50 PM, Anselm Kruis <span dir="ltr"><<a href="mailto:a.kruis@science-computing.de" target="_blank">a.kruis@science-computing.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Lars,<br>
<br>
you are observing well known deficiencies of the pickle/cPickle implementation of Python. Perhaps sPickle (<a href="http://pypi.python.org/pypi/sPickle" target="_blank">http://pypi.python.org/pypi/<u></u>sPickle</a>) can pickle the channels.<br>
<br>
Regards<br>
Anselm<br>
<br>
<br>
Am <a href="tel:06.10.2013%2008" value="+31610201308" target="_blank">06.10.2013 08</a>:58, schrieb lars van Gemerden:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
maybe double but i got a mail bounce ..<br>
<br>
---------- Forwarded message ----------<br>
From: lars van Gemerden <<a href="mailto:lars@rational-it.com" target="_blank">lars@rational-it.com</a>><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" target="_blank">stackless@stackless.com</a>><br>
<br>
<br>
actually both give an error. The only thing different is the error message.<br>
with pickle the code would be:<br>
<br>
------------------------------<u></u>------------------------------<u></u>---------------<br>
import stackless, pickle<br>
<br>
class Test(object):<br>
def __init__(self):<br>
self.channel = stackless.channel()<br>
<br>
def run(self):<br>
stackless.tasklet(self.sender)<u></u>()<br>
stackless.tasklet(self.<u></u>receiver)()<br>
stackless.run()<br>
<br>
def sender(self):<br>
counter = 0<br>
while counter < 10:<br>
self.channel.send(counter)<br>
counter += 1<br>
<br>
def receiver(self):<br>
counter = 0<br>
while counter < 12:<br>
counter = self.channel.receive()<br>
print counter,<br>
print "done"<br>
<br>
if __name__ == "__main__":<br>
<br>
t = Test()<br>
t.run()<br>
t.channel = None<br>
s = pickle.dumps(t) #OK<br>
<br>
t = Test()<br>
t.run()<br>
s = pickle.dumps(t) #ERROR<br>
------------------------------<u></u>------------------------------<u></u>-----------------<br>
and the error:<br>
<br>
pickle.PicklingError: Can't pickle <type 'function'>: it's not found as<br>
__builtin__.function<br>
<br>
otherwise the error behavior is the same as decribed above.<br>
<br>
Cheers, Lars<br>
<br>
(as far as i have read and tested a bit, deepcopy allows more to be copied<br>
then pickle, but cPickle is faster, so i have my own deepcopy:<br>
<br>
def deepcopy(obj):<br>
try:<br>
return cPickle.loads(cPickle.dumps(<u></u>obj, -1))<br>
except PicklingError:<br>
return copy.deepcopy(obj)<br>
)<br>
<br>
<br>
On Thu, Oct 3, 2013 at 5:19 AM, Richard Tew <<a href="mailto:richard.m.tew@gmail.com" target="_blank">richard.m.tew@gmail.com</a>> wrote:<br>
<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>
______________________________<u></u>_________________<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/<u></u>mailman/listinfo/stackless</a><br>
<br>
</blockquote>
<br>
<br>
<br>
<br>
<br>
maybe double but i got a mail bounce ..<br>
<br>
---------- Forwarded message ----------<br></div></div><div class="im">
From: *lars van Gemerden* <<a href="mailto:lars@rational-it.com" target="_blank">lars@rational-it.com</a><br>
<mailto:<a href="mailto:lars@rational-it.com" target="_blank">lars@rational-it.com</a>>><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" target="_blank">stackless@stackless.com</a><br></div><div><div class="h5">
<mailto:<a href="mailto:stackless@stackless.com" target="_blank">stackless@stackless.<u></u>com</a>>><br>
<br>
<br>
actually both give an error. The only thing different is the error<br>
message. with pickle the code would be:<br>
<br>
------------------------------<u></u>------------------------------<u></u>---------------<br>
import stackless, pickle<br>
<br>
class Test(object):<br>
def __init__(self):<br>
self.channel = stackless.channel()<br>
def run(self):<br>
stackless.tasklet(self.sender)<u></u>()<br>
stackless.tasklet(self.<u></u>receiver)()<br>
stackless.run()<br>
def sender(self):<br>
counter = 0<br>
while counter < 10:<br>
self.channel.send(counter)<br>
counter += 1<br>
def receiver(self):<br>
counter = 0<br>
while counter < 12:<br>
counter = self.channel.receive()<br>
print counter,<br>
print "done"<br>
if __name__ == "__main__":<br>
t = Test()<br>
t.run()<br>
t.channel = None<br>
s = pickle.dumps(t) #OK<br>
t = Test()<br>
t.run()<br>
s = pickle.dumps(t) #ERROR<br>
------------------------------<u></u>------------------------------<u></u>-----------------<br>
and the error:<br>
<br>
pickle.PicklingError: Can't pickle <type 'function'>: it's not found as<br>
__builtin__.function<br>
<br>
otherwise the error behavior is the same as decribed above.<br>
<br>
Cheers, Lars<br>
<br>
(as far as i have read and tested a bit, deepcopy allows more to be<br>
copied then pickle, but cPickle is faster, so i have my own deepcopy:<br>
<br>
def deepcopy(obj):<br>
try:<br>
return cPickle.loads(cPickle.dumps(<u></u>obj, -1))<br>
except PicklingError:<br>
return copy.deepcopy(obj)<br>
)<br>
<br>
<br>
On Thu, Oct 3, 2013 at 5:19 AM, Richard Tew <<a href="mailto:richard.m.tew@gmail.com" target="_blank">richard.m.tew@gmail.com</a><br></div></div><div class="im">
<mailto:<a href="mailto:richard.m.tew@gmail.com" target="_blank">richard.m.tew@gmail.<u></u>com</a>>> wrote:<br>
<br>
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>
______________________________<u></u>_________________<br>
Stackless mailing list<br></div>
<a href="mailto:Stackless@stackless.com" target="_blank">Stackless@stackless.com</a> <mailto:<a href="mailto:Stackless@stackless.com" target="_blank">Stackless@stackless.<u></u>com</a>><div class="im"><br>
<a href="http://www.stackless.com/mailman/listinfo/stackless" target="_blank">http://www.stackless.com/<u></u>mailman/listinfo/stackless</a><br>
<br>
<br>
<br>
<br>
--<br>
==============================<u></u>======<br>
Lars van Gemerden<br>
</div><a href="mailto:lars@rational-it.com" target="_blank">lars@rational-it.com</a> <mailto:<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> <tel:%2B31%206%2026%2088%2055%<u></u>2039><div class="im"><br>
==============================<u></u>======<br>
<br>
<br>
<br>
--<br>
==============================<u></u>======<br>
Lars van Gemerden<br>
</div><a href="mailto:lars@rational-it.com" target="_blank">lars@rational-it.com</a> <mailto:<a href="mailto:lars@rational-it.com" target="_blank">lars@rational-it.com</a>><div class="im"><br>
<a href="tel:%2B31%206%2026%2088%2055%2039" value="+31626885539" target="_blank">+31 6 26 88 55 39</a><br>
==============================<u></u>======<br>
<br>
<br></div><div class="im">
______________________________<u></u>_________________<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/<u></u>mailman/listinfo/stackless</a><br>
<br>
</div></blockquote><span class="HOEnZb"><font color="#888888">
<br>
-- <br>
Dipl. Phys. Anselm Kruis science + computing ag<br>
Senior Solution Architect Ingolstädter Str. 22<br>
email <a href="mailto:A.Kruis@science-computing.de" target="_blank">A.Kruis@science-computing.de</a> 80807 München, Germany<br>
phone <a href="tel:%2B49%2089%20356386%20874" value="+4989356386874" target="_blank">+49 89 356386 874</a> fax 737 <a href="http://www.science-computing.de" target="_blank">www.science-computing.de</a><br>
-- <br>
Vorstandsvorsitzender/Chairman of the board of management:<br>
Gerd-Lothar Leonhart<br>
Vorstand/Board of Management:<br>
Dr. Bernd Finkbeiner, Michael Heinrichs, Dr. Arno Steitz, Dr. Ingrid Zech<br>
Vorsitzender des Aufsichtsrats/<br>
Chairman of the Supervisory Board:<br>
Philippe Miltin<br>
Sitz/Registered Office: Tuebingen<br>
Registergericht/Registration Court: Stuttgart<br>
Registernummer/Commercial Register No.: HRB 382196</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
______________________________<u></u>_________________<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/<u></u>mailman/listinfo/stackless</a><br>
</div></div></blockquote></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>