Thanks Tom, I'll take a look a those docs. The requestHandler in question is actually just a standard class with 6 methods - options(), head(), get (), post(), put() and delete() - and I have a whole stack of them - roughly one for every resource URI pattern in a RESTful application. My app allows user submitted handlers, so I stick the min the database, and load them up on the first resource request. Rather than load them up every requst, I want to have them in memcache.
So just to clarify - you think that error message is an indication that the structure of the object is the problem, rather than not being able to locate its definition? Cheers, Colin PS - Google - please fix - http://code.google.com/p/googleappengine/issues/detail?id=671 On Dec 2, 12:00 am, Tim Hoffman <[EMAIL PROTECTED]> wrote: > Have a look at pickle docs, you will see that a class needs a > getstate,setstate methods to > support pickling. Large/complex instances of classes won't pickle out > of the box think about > classes like request handlers have many subobjects and pickle wouldn't > know how to deal with > this. > > Rgds > > Tim > > P.S. I am not sure why you would want to cache a request handler in > the first place though. > > On Dec 2, 3:08 am, hawkett <[EMAIL PROTECTED]> wrote: > > > It occurred to me that pickle may have looked *everywhere* else, and > > __builtin__ is just the last place it looked, which explains the > > error. So perhaps I just need to install my class definition > > *anywhere* that pickle can find it. Still the question stands though - > > what's the best approach to achieve what I am trying to do? Thanks. > > > On Dec 1, 5:26 pm, hawkett <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > This might be a generic pythin question, but since I'm running into > > > an issue on GAE with memcache, this is probably a good place to ask. > > > > I've got the following code > > > > opGlobals = {} > > > exec(requestHandlerCode, opGlobals) > > > requestHandler = opGlobals["RequestHandler"]() > > > memcache.add(key="requestHandler", value=requestHandler) > > > > where 'requestHandlerCode' from the second line is just a python class > > > definition retrieved from a TextProperty in the datastore. Lines 1-3 > > > execute fine, and I can call methods on the class instantiated in line > > > 3. However, trying to put the instance into memcache as in line 4 > > > generates the following error - > > > > PicklingError: Can't pickle <class __builtin__.RequestHandler at > > > 0x17ef0c0>: it's not found as __builtin__.RequestHandler > > > > Which is fine - I understand that it needs to be able to find the > > > class definition in order to pickle/unpickle the object - what I'm not > > > sure of is the best approach to resolving the problem. I could put > > > the code in memcache, but then I'd be compiling and instantiating it > > > every request, which is no good. > > > > The obvious options seem to be - > > > > 1. Install the class definition in __builtin__ so pickle does know > > > what to do with it (feels like a hack?) > > > 2. Tell pickle to also look elsewhere for the information it needs > > > > If someone who knows python better than I do could point me in the > > > right direction, that would be great. Cheers, > > > > Colin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
