[Zope] - BoboPOS problems

Jim Fulton jim@Digicool.com
Thu, 17 Dec 1998 20:07:14 +0000


Pavlos Christoforou wrote:
> 
> Hello Zopistas
> 
> I created an extension (a hit counter) that includes the class
> definition in the same source file as the method. After a couple of days
> ZopeHTTPServer crashed without any apparent reason. On restarting I got
> the following errors in the server.log file:
> 
> Traceback (innermost last):
>   File "serve.py", line 99, in ?
>     ZopeHTTPServer.main(args)
>   File "/home/pavlos/Zope-1.9.0b2-src/ZopeHTTPServer/ZopeHTTPServer.py", line 456, in main
>     start(module_file,host,port,threading,env)
>   File "/home/pavlos/Zope-1.9.0b2-src/ZopeHTTPServer/ZopeHTTPServer.py", line 405, in start
>     set_published_module(module_file,BoboRequestHandler,env)
>   File "/home/pavlos/Zope-1.9.0b2-src/ZopeHTTPServer/ZopeHTTPServer.py", line 401, in set_published_module
>     __import__(name) # to catch problem modules right away
>   File "/home/pavlos/Zope-1.9.0b2-src/lib/python/Main.py", line 103, in ?
>     Bobobase=OFS.Application.open_bobobase()
>   File "/home/pavlos/Zope-1.9.0b2-src/lib/python/OFS/Application.py", line 319, in open_bobobase
>     app._setObject('Control_Panel', cpl)
>   File "/home/pavlos/Zope-1.9.0b2-src/lib/python/BoboPOS/PickleJar.py", line 261, in setstate
>     state = unpickler.load()
> SystemError: Failed to import class Counter from module __main__

I need to figure out a way to handle this more gracefully.
 
> As I understand the problem has to do with pickle not finding the class
> definition. I assume that the External methods object uses exec to load
> and store only the function definition into Zope/BoboPOS and not any other
> code that finds in the source file.

Yes.
 
> I hacked Main.py and included a
> from Counter import Counter

You are close.  Try:

import __main__, Counter
__main__.Counter=Counter.Counter 

> but it did not work. So now I am stuck without Zope :-(
> Also the change was made 2 days ago and all objects from there on include
> refrences to the counter object.
> 
> Am I missing something simple or have I messed things up badly?

It would be a good idea to avoid creating persistent objects in
external methods.  If an external method wants new
classes that get pickled, it should:

  - Become a product, or

  - Use a class defined in a module in the package
    (or a subpackage of the package):

      Shared.your_org

    where your_org is your organization or name.

Maybe I should add an option to cPickle to make it
barf if an attempt is made to pickle an object in
__main__.


Jim

--
Jim Fulton           mailto:jim@digicool.com
Technical Director   (540) 371-6909              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.