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?
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/)
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 )
Thanks to Chris & Guido I have something that works. A quick recap: Learned that: 1. Pickling a class involves a 'locatable' class definition on both the pickling and unpickling operations. 2. Where to move it? Ended up in site-packages, named the package folder and module the same thing and discovered the true meaning of from {package} import {module}. 3. Zope external modules only see the code involved in the specified call, so calling a module with an internal class definition ( that works in python ) will fail as an external method because zope ignores it. Resolved the problem by importing the package/module/class from site-packages, which enables zope's external methods to locate the class. Next question: At Chris's suggestion I'd like to move the code from the external method to the site-package, leaving just a stub for the external methods. Same problem all over again. Zope sees the functions in the modules, but not the class defined in the module. Tried a quick experiment, created a separate file for the code in the site-package, and imported the class from the adjacent file. Zope still can't see it. So before I start flailing about I thought I'd see if anyone else has experienced a similar situation, and how they resolved it. I can see a possible solution in creating two 'site-packages', one for the code and one for the class. But that's just a guess, and it lacks a certain elegance! Je ne sais quoi, Sean
Same problem all over again. Zope sees the functions in the modules, but not the class defined in the module. Tried a quick experiment, created a separate file for the code in the site-package, and imported the class from the adjacent file. Zope still can't see it.
When you say "Zope still can't see it", what do you mean? What is the actual error condition? Can you boil the problem down to a small test case? - C
participants (4)
-
Chris McDonough -
Guido van Rossum -
Sean Duffy -
stuffduff