如何腌制记录仪? [英] How to pickle loggers?

查看:86
本文介绍了如何腌制记录仪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在从事一个要求我能够在任何时候对容器对象进行腌制的项目,因为我们希望它在外部条件下经常发生故障,并且能够完全从我们中断的地方捡起.

Working on a project that requires that I am able to pickle the container object at any point, since we expect it to fail on external conditions quite frequently and be able to fully pick up where we left off.

我正在广泛使用python日志记录库,并且我所有的类都始于设置像logger这样的记录器:

I'm using the python logging library quite extensively, and all of my classes start by setting up a logger like:

class foo:
   def __init__(self):
       self.logger = logging.getLogger("package.foo")

由于我要腌制一个容器类,因此其中包含多层类,每个类都有自己的记录器实例.

Since I'm pickling a container class, it has several layers of classes within it, each with their own logger instance.

现在,由于某些原因,这些记录器正在破坏Pickle.我收到以下错误,如果我从所有类中删除self.logger,该错误将消失:

Now, for some reason, these loggers are breaking Pickle. I'm getting the following error, which goes away if I delete self.logger from all the classes:

Can't pickle 'lock' object: <thread.lock object at ... >

所以我的问题是是否有某种方法可以从所有记录器中删除锁定对象,而不必通过整个对象树递归删除删除的记录器,而这些记录器将不得不在重新修复时重新创建.

So my question is whether or not there is some way to remove the lock objects from all the loggers without having to recurse through my whole object tree deleting loggers which I will have to recreate on unpickle.

推荐答案

在这里找到了一个非常相似的问题,给出了一个对我有用的答案:

Found a very similar question here, with an answer that worked for me:

如何阻止在Python中腌制属性

使用以下答案:如何阻止在Python中对属性进行腌制

这篇关于如何腌制记录仪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆