unpickling derived LogRecord in python 2.7 from python2.6

ivdneut at gmail.com ivdneut at gmail.com
Fri Apr 29 04:36:23 EDT 2011


On Apr 28, 9:22 am, Peter Otten <__pete... at web.de> wrote:
> Vinay Sajip wrote:
> > On Apr 27, 5:41 pm, Peter Otten <__pete... at web.de> wrote:
>> >> The Problem is that as of Python 2.7logging.LogRecord has become a
> >> newstyle class which is pickled/unpickled differently. I don't know if
> >> there is an official way to do the conversion, but here's what I've
> >> hacked up. The script can read pickles written with 2.6 in 2.7, but not
> >> the other way round.
> >> [code snipped]
>> > I don't know about "official", but another way of doing this is to
> > pickle just the LogRecord's __dict__ and send that over the wire. The
> > logging package contains a function makeLogRecord(d) where d is a
> > dict.
>> You are right, my approach is too complicated and only needed when the OP
> cannot modify the sending script -- which is unlikely.
>> > This is the approach used by the examples in the library documentation
> > which pickle events for sending across a network:
>> >http://docs.python.org/howto/logging-cookbook.html#sending-and-receiv...
>> logging-events-across-a-network
>>>> > The built-in SocketHandler pickles the LogRecord's __dict__ rather
> > than the LogRecord itself, precisely because of the improved
> > interoperability over pickling the instance directly.
>> As a minimal change ensuring that the logging.LogRecord subclass used by the
> OP is a newstyle class in 2.6 with
>> class LogRecord(logging.LogRecord, object):
>     #...
>> should work, too.

I tried this, but it didn't work. Pickling the __dict__ and then use
makeLogRecord does the trick.
Thank you very much for the excellent help,
Ian.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /