Hi,

I am using one of my web2py models outside of web2py, in a script intended 
to be run from command line. I am importing the models of web2py (to get 
access to my database definitions and other models) using this code-snippet:

def _importWeb2py():
   rundir = os.getcwd()
   WEB2PY_PATH = rundir + "/../../../MyApp/web2py/"
   os.chdir(WEB2PY_PATH)
   sys.path.append(WEB2PY_PATH)
   from gluon.shell import env
   globals().update(env('MyApp', import_models=True))

One of my models defines a container object (shortened to be more easily 
readable):

class RawDataPost():
   def __init__(self, id, data):
      self.id = id
      self.data = data

When I try to pickle the container object I get the following error:
pickle.PicklingError: Can't pickle <class __restricted__.RawDataPost at 
0x9661b6c>: it's not found as __restricted__.RawDataPost

If I move the definition of RawDataPost into the external script, the 
pickling works fine (so the object is perfectly picklable).

I would however want to avoid copying / moving the definition of 
RawDataPost and use the above import. Any idea what that restricted 
buisness means? And can I get around it somehow? Googling left me equally 
dumbfounded.

-- 



Reply via email to