[Zope-dev] RE: Curious Problem

Chris McDonough chrism@zope.com
25 Apr 2003 17:24:43 -0400


I don't know exactly how this is true (as we haven't seen the code), but
I think the root of the misunderstanding in this situation may be that
the file in which external methods are defined is not a standard Python
module.  It's a file in which you define things that look a lot like
functions (and internally are converted to functions), but it doesn't
have the same behavior as a standard Python module.  Classes and other
objects defined in the file may not addressable by the pickling
machinery in the normal way.

I might try moving the classes you're instantiating to a module that is
on the PYTHONPATH and see what happens.

Seeing your code would help too.

On Fri, 2003-04-25 at 17:10, Guido van Rossum wrote:
> > I've spent most of the day recreating the setup from scratch, just to rule
> > out a python problem.
> > 
> > I built python 2.1.3 from source, then used that python (renamed
> > python2.1.3) to build zope from src.
> > 
> > I can still run from the command line, but not from zope; same error as
> > before.
> > 
> > One thing I tried was to move the class definition inside the function
> > definition
> > (how could zope miss it? ;) ) but still no joy.
> > 
> > I just don't understand why zope even needs to see the class.
> > 
> > The function reads a record from an rdbms, unpickles and uses a few object
> > properties to build a string.  Something in zope itself seems to be
> > preventing this.
> > 
> > Any other thoughts?
> 
> Are you sure you understand what you are doing?  Moving a class
> definition used by a pickle *inside* a function is a sure recipe for
> disaster (the unpickling code can only find classes defined at the
> top level in a module).
> 
> The error message (SystemError: Failed to import class MyObject from
> module __main__) indicates that when the class instance was pickled,
> it was in the __main__ module (i.e. in the script that you passed to
> the python command line).  There is no way that an external method can
> define a class in that module.
> 
> It would help if you posted your code.
> 
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> 
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://mail.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists - 
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope )