More info:

I've confirmed that any class defined in the modules directory can
reproduce the problem.  To verify,  create a new module named
"dummyclass.py" containing

import uuid
class Problem(object):
    """ Just to validate that session.problem pickling error
        is not related to anything in PTProblem class.

    """
    def __init__(self,description,ownerid=0):
        self.uuid = uuid.uuid1()


and alter the local_import statement in my previous post to look like:

PTProblemClass = local_import('dummyclass',reload=True)

Thanks,
Mike


On May 6, 2:07 pm, MikeEllis <[email protected]> wrote:
> The class isn't really named Foo, of course, but it makes for a more
> readable subject line.
>
> Here's the actual ticket:
>
> Traceback (most recent call last):
>   File "/Users/mellis/web2py/gluon/main.py", line 504, in wsgibase
>     session._try_store_on_disk(request, response)
>   File "/Users/mellis/web2py/gluon/globals.py", line 375, in
> _try_store_on_disk
>     cPickle.dump(dict(self), response.session_file)
> PicklingError: Can't pickle <class
> 'applications.peertool.modules.PTProblemClass.Problem'>: it's not the
> same object as applications.peertool.modules.PTProblemClass.Problem
>
> And here is a simple default.py that reliably reproduces the error:
>
> import cPickle
> PTProblemClass = local_import('PTProblemClass',reload=True)
>
> def mytest():
>
>     ## Create an instance of class Problem and prove that it
>     ## can be pickled.
>     problem = PTProblemClass.Problem("Just testing ...",ownerid=2)
>     filename = 'problem_' + str(problem.uuid)
>     PROBLEMFILEPATH =
> os.path.join('applications','peertool','private')
>     f = open(os.path.join(PROBLEMFILEPATH,filename),'w')
>     cPickle.dump(problem,f)
>     f.close()
>
>     ## Assign to session.problem and show that it is
>     ## an instance of the class
>     session.problem = problem
>     assert isinstance(session.problem, PTProblemClass.Problem)
>
>     ## Return a message of comfort and cheer
>     return dict(message=T("Test completed"))
>
> def index():  ## Unaltered from new app creation
>     """
>     example action using the internationalization operator T and flash
>     rendered by views/default/index.html or views/generic.html
>     """
>     response.flash = T('Welcome to web2py')
>     return dict(message=T('Hello World'))
>
> I've not included the Problem class code. It's proprietary and I'm
> reasonably convinced its not part of the problem since there are no
> problems pickling (or unpickling) instances of it.
>
> I can reproduce the problem by the following steps:
> 1. Visit the index page, no ticket.
> 2. Visit mytest, no ticket
> 3. Visit index page again, get the ticket.
>
> I'm running web2py 1.74.9.
>
> Anyone know how to solve this?  It's a particularly annoying because
> once the error occurs, the entire app is hosed until I visit the site
> page and clean the sessions and caches.
>
> Thanks,
> Mike

Reply via email to