made some more simple test cases (pickling Test1() and Test2() fails):

#-------------------------------------------------------------
import pickle

def func(): pass

class Test0(object):
    def __init__(self):
        self.func = func

class Test1(object):
    def __init__(self):
        self.func = lambda s: 0

class Test2(object):
    def __init__(self):
        self.func = self.func2
    def func2(self):
        pass


if __name__ == '__main__':

    s = pickle.dumps(Test0())
    t = pickle.loads(s)
    s = pickle.dumps(Test1()) #ERROR
    t = pickle.loads(s)
    s = pickle.dumps(Test2()) #ERROR
    t = pickle.loads(s)
    print 'done'
#-------------------------------------------------------------

all succeed in e.g. Idle.

Cheers, Lars



On Thu, Oct 24, 2013 at 4:52 PM, Kristján Valur Jónsson <
[email protected]> wrote:

>
> > -----Original Message-----
> > From: [email protected] [mailto:stackless-
> > [email protected]] On Behalf Of John Ehresman
> > Sent: 23. október 2013 15:06
> > To: [email protected]
> > Subject: Re: [Stackless] Fwd: deepcopying (pickling) channels
> >
> > It does look like the __init__ saves a reference of self.func2 in
> self.func -- is
> > this what triggers the pickling of globals?
>
> Yes.  It is trying to pickle a bound function.
> But it is not pickling "globals".  save_global() means that it is trying
> to save an object by name.  It came across wingdb_import_hook during the
> process, and this function is not found where it says it is found.
> Now, where did it find the function?  We don't know.
> If you change pickle.py we might have a better idea.
>
> How about this:
>
> def save(self, obj):
>   try:
>     return self._save(obj)
>   except PickleError:
>     print "pickling obj: %r", obj
>     raise
>
> def _save(self, obj):
>   ... #rename old save to _save.
>
>
> This should give us more info.
>
> K
>
>
> _______________________________________________
> Stackless mailing list
> [email protected]
> http://www.stackless.com/mailman/listinfo/stackless
>



-- 
====================================
Lars van Gemerden
[email protected]
+31 6 26 88 55 39
====================================
_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless

Reply via email to