Re: Is pickling of generator still supported in 3.3?

Christian Tismer <[email protected]> Fri, 26 Sep 2014 21:42:53 +0200
Newsgroups gmane.comp.python.stackless
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============1124945503359073970==
Content-Type: multipart/alternative;
 boundary="------------060305020009090904030005"

This is a multi-part message in MIME format.
--------------060305020009090904030005
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 26.09.14 20:43, Christian Tismer wrote:
> Hi Wen,
>
> On 09.09.14 18:58, Wen Tao wrote:
>> I was able to pickle a generator in the stackless python 2.7 version,
>> the code I use is:
>>
>> def process():
>> yield 0
>> yield 1
>>
>> gen =3D process()
>> print(gen.send(None))
>> import pickle
>> print(pickle.dumps(gen))
>>
>> But in the stackless python 3.3 version (which I downloaded source
>> code and compiled in a Ubuntu 12.04 amd64 box), the code can not run.
>> The error message read was:
>>
>> 0
>> Traceback (most recent call last):
>>   File "test.py", line 8, in <module>
>>     print(pickle.dumps(gen))
>> _pickle.PicklingError: Can't pickle <class 'generator'>: attribute
>> lookup builtins.generator failed
>>
>> Is this a feature? Or deserve a bug fix?
>>
>
> This does of course deserve a bug fix.
> Looking into that ...

First result on Python 3.4:

If you disable the fast pickling mode, then it works in 3.4.
In line 1590 of pickle.py you can change the _pickle name to something
else, then the interpreted version of pickle will be used.

Obviously, something inhibits our machinery from doing its work.
On 2.7, it both works with pickle and cPickle.

So the general answer for now:
It should work, some builtin check prevents that, and we are missing
a test for that as well.

Will work on that, later. Filing a bug.

cheers - Chris

--=20
Christian Tismer             :^)   [email protected]
Software Consulting          :     http://www.stackless.com/
Karl-Liebknecht-Str. 121     :     http://www.pydica.net/
14482 Potsdam                :     GPG key -> 0xFB7BEE0E
phone +49 173 24 18 776  fax +49 (30) 700143-0023


--------------060305020009090904030005
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 26.09.14 20:43, Christian Tismer
      wrote:<br>
    </div>
    <blockquote cite="mid:[email protected]" type="cite">
      <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
      <div class="moz-cite-prefix">Hi Wen,<br>
        <br>
        On 09.09.14 18:58, Wen Tao wrote:<br>
      </div>
      <blockquote
cite="mid:CALgWZBrbkAbtWAJOuh=h4bWnfyQi680tOzT36+w67GyTqzMM9A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org"
        type="cite">
        <div dir="ltr">I was able to pickle a generator in the stackless
          python 2.7 version, the code I use is:
          <div><br>
          </div>
          <div>
            <div>def process():</div>
            <div><span class="" style="white-space:pre"> </span>yield 0</div>
            <div><span class="" style="white-space:pre"> </span>yield 1</div>
            <div><br>
            </div>
            <div>gen = process()</div>
            <div>print(gen.send(None))</div>
            <div>import pickle</div>
            <div>print(pickle.dumps(gen))</div>
          </div>
          <div><br>
          </div>
          <div>But in the stackless python 3.3 version (which I
            downloaded source code and compiled in a Ubuntu 12.04 amd64
            box), the code can not run. The error message read was:</div>
          <div><br>
          </div>
          <div>
            <div>0</div>
            <div>Traceback (most recent call last):</div>
            <div>  File "test.py", line 8, in &lt;module&gt;</div>
            <div>    print(pickle.dumps(gen))</div>
            <div>_pickle.PicklingError: Can't pickle &lt;class
              'generator'&gt;: attribute lookup builtins.generator
              failed</div>
          </div>
          <div><br>
          </div>
          <div>Is this a feature? Or deserve a bug fix?</div>
        </div>
        <br>
      </blockquote>
      <br>
      This does of course deserve a bug fix.<br>
      Looking into that ...<br>
    </blockquote>
    <br>
    First result on Python 3.4:<br>
    <br>
    If you disable the fast pickling mode, then it works in 3.4.<br>
    In line 1590 of pickle.py you can change the _pickle name to
    something<br>
    else, then the interpreted version of pickle will be used.<br>
    <br>
    Obviously, something inhibits our machinery from doing its work.<br>
    On 2.7, it both works with pickle and cPickle.<br>
    <br>
    So the general answer for now:<br>
    It should work, some builtin check prevents that, and we are missing<br>
    a test for that as well.<br>
    <br>
    Will work on that, later. Filing a bug.<br>
    <br>
    cheers - Chris<br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Christian Tismer             :^)   <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
Software Consulting          :     <a class="moz-txt-link-freetext" href="http://www.stackless.com/">http://www.stackless.com/</a>
Karl-Liebknecht-Str. 121     :     <a class="moz-txt-link-freetext" href="http://www.pydica.net/">http://www.pydica.net/</a>
14482 Potsdam                :     GPG key -&gt; 0xFB7BEE0E
phone +49 173 24 18 776  fax +49 (30) 700143-0023
</pre>
  </body>
</html>

--------------060305020009090904030005--


--===============1124945503359073970==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless
--===============1124945503359073970==--