Re: Pickling errors with tz.FixedOffsetTimezone

Daniele Varrazzo <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <1232196610.10862.22.camel@ikki>
On Sat, 2009-01-17 at 12:13 +0100, Lawrence Oluyede wrote:
> On Sat, Jan 17, 2009 at 11:51 AM, Federico Di Gregorio <fog-NGVKUo/i/[email protected]> wrote:
> > Il giorno ven, 16/01/2009 alle 13.22 +0100, Lawrence Oluyede ha scritto:
> >> I have a web application that uses memcached to store some data.
> >> Some of that data is retrieved through psycopg2 (2.0.8) and contains
> >> datetime instances.
> >>
> >> Sometimes I get the following exception while trying to put objects
> >> into the memcached cache:
> >> "PicklingError: Can't pickle <class
> >> 'psycopg2.tz.FixedOffsetTimezone'>: it's not the same object as
> >> psycopg2.tz.FixedOffsetTimezone"
> >
> > Once I was bitten by a very similar error. The module was loaded two
> > times from different paths and instances created with the first copy of
> > the module could not be pickled by the code that had the second copy
> > available. I didn't dig too much to understand what was happening
> > because we were in a hurry and simply making sure the was a single copy
> > of the module solved the problem.
> 
> Thanks, I'll try to do an in depth check of the program. Maybe there's
> some dependence that I'm not seeing in the surface triggering this
> kind of bad behavior. It's odd though.
> 

That happened to me too sometimes, importing a module once with a
complete packages path and somewhere into a sibling module using only
the module name. The result was having distinct foo.bar.MyClass and
bar.MyClass, and the isinstance test failing here and there.

You may try:

    for n, m in sys.modules.iteritems():
        c =  getattr(m, 'FixedOffsetTimezone', None) 
        if c: print n, id(c)

If somewhere the class has a different id, it may have been imported in
a strange way.

Bye!


-- Daniele
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.